TikZ
- Pic or Shape for collection of ready to use objects?by Sammy on December 31, 2025 at 2:25 pm
For the graphics I use on my physics exercise sheets made with TikZ I often use the same objects (hooks, masses, carts, pulleys, force gauges,...). So instead of copy-pasting and modifying the code of these objects I think it makes sense to make them into a ready to use object. There are three ways I know of to make that happen: TeX macros, pics and shapes. There are some features I wish the implementation of these objects to have and need some advice on how to implement it in order to have those features: An object should have multiple anchors so I can easily use certain points for further construction and choose which anchor to use for the placement (so there is no need to calculate that stuff manually). The hook for example could be placed at it's base or the actual hook and either one should be available afterwards for further placement of objects or paths. A default style should be set, i.e. the fill color or shading of the mass body, that can be overwritten. If placed inside a scope that changes shift, rotation, scale, line width,... these changes should automatically also apply to the object as a whole. I want to be able to construct new objects from already existing objects, i.e. I want to be able to use the hook as part of the mass, force gauge and cart. Right now I'm leaning towards defining new shapes, even tho I haven't used low level pgf before. As far as I can see 1 and 3 are no problem with shapes. I feel like 2 could also be achieved (any hints are appreciated - maybe defining a new style that uses that shape?). I however have no Idea if or how to make 4 work in defining a new shape. Pics on the other hand would make 2 and 4 easy as far as I can imagine. But they don't respond to the settings of a scope (3). Also anchors (1) are not natively supported but using tikzmark one answer to this question Anchoring TiKZ pics suggests this could be achieved as well (although I imagine it to be not quite as powerful as a new shape and takes two compilation runs if I understood correctly). Any thoughts, hints or pieces of advice are very welcome. I hope I described the setting clear enough. Edit The following Example is not meant to be beautiful but hopefully helps to illustrate the issue: \documentclass[tikz]{standalone} \usetikzlibrary{calc} \usetikzlibrary{tikzmark} \begin{document} \tikzset{ hook/.pic={ \draw[double=gray!80, double distance=1.4pt] (0,0) .. controls (0,-1.5) and (0,{1/sin(45)-2.5}) .. ($(45:1)+(0,-2.5)$) arc(405:140:1); \node[inner sep=2mm] (-hole) at (0,-2.5) {}; } } \tikzset{ cart/.pic={ \shadedraw[left color=blue, right color=blue!50] (-3,0) rectangle (3,2); \shadedraw[left color=black, right color=gray] (2,-.8) circle (.8); \shadedraw[left color=black, right color=gray] (-2,-.8) circle (.8); \pic[transform shape,rotate=90,scale=.5] (h) at (3,1) {hook}; \coordinate (-front-wheel) at (2,-1.6); \coordinate (-back-wheel) at (-2,-1.6); \node[inner sep=2mm] (-hook) at (h-hole) {}; } } \begin{tikzpicture} \draw (0,0) -- (8,0) -- (8,2); \pic[pic anchor=(-back-wheel),scale=.5] (cart) at (.5,0) {cart}; \pic[rotate=270,xscale=-1,scale=.25] (hook) at (8,0|-cart-hook) {hook}; \draw[ultra thick, line cap=round] (cart-hook) -- (hook-hole); \end{tikzpicture} \end{document} So using a pic with tikzmark (and transform shape as I've discovered) seems to check all the requirements. Can this also be achieved with a custom shape? As in this solution I dislike a few things: tikzmark needs two compilation runs no border anchors can be defined (at least I don't know how) It seems to me all anchors are defined every time a pic is inserted and not calculated when needed as with shapes. I'm not sure about the impacts on compilation time.
- Could you add "Happy New Year" in your language? Have a wonderful 2026!by Ñupi on December 31, 2025 at 3:11 am
\documentclass[aspectratio=169]{beamer} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{tikz} \usetikzlibrary{shapes.geometric, shadings, shadows} \setbeamertemplate{navigation symbols}{} \begin{document} \begin{frame}[plain] \begin{tikzpicture}[remember picture, overlay] \fill[top color=blue!20!black, bottom color=black] (current page.south west) rectangle (current page.north east); \foreach \i in {1,...,60} { \fill[white, opacity=0.4] (current page.center) ++({rand*8}, {rand*4.5}) circle (0.03); } \node[white, opacity=0.75, font=\small\itshape] at (-5, 2.5) {Happy New Year}; % \node[white, opacity=0.75, font=\small\itshape] at (5, -2.5) {Bonne Année}; \node[align=center, text=white] at (current page.center) { {\fontsize{35}{40}\selectfont \textbf{\textcolor{yellow!70!white}{¡Happy New Year!}}} \\[0.3cm] {\fontsize{20}{24}\selectfont \textit{and prosperous}} \\[0.5cm] {\fontsize{75}{75}\selectfont \textbf{\textcolor{white}{2026}}} \\[0.8cm] {\fontsize{18}{22}\selectfont \textsf{\textbf{Friends of \LaTeX}}} }; \draw[very thick, orange!60!yellow, opacity=0.6] (-4,-1.8) -- (4,-1.8); \shade[ball color=yellow, opacity=0.3] (-7, 3) circle (0.5); \shade[ball color=orange, opacity=0.2] (7, -3) circle (0.8); \end{tikzpicture} \end{frame} \end{document}
- Drawing Only a Portion of an Oval Frameby DDS on December 30, 2025 at 10:39 pm
Consider the following code which I compile with xelatex: \documentclass{book} \usepackage{graphicx} \usepackage[abs]{overpic} \usepackage{tikz} \definecolor{cadmiumgreen}{rgb}{0.0, 0.42, 0.235} % 0, 107, 60 \definecolor{Gold}{RGB}{228,168,73} \begin{document} \thispagestyle{empty} \begin{center} \begin{tikzpicture} \clip (0,0) ellipse (4.25cm and 5.5cm); \draw[line width=5pt,Gold,fill=cadmiumgreen] ellipse (4.25cm and 5.5cm); \node at (0,0) {\includegraphics[scale=.37,clip, trim = 0 0 0 0]{example-image-a}}; \draw[line width=12pt,Gold!70!black] ellipse (4.25cm and 5.5cm); \end{tikzpicture} \end{center} \end{document} with the output: QUESTION: How may I draw only a part of the 12pt-thick oval frame; in particular, relative to the node (0,0), draw the frame from only -45 degrees to 225 degrees in a clockwise fashion (instead of from -90 degrees to 270 degrees which gives the entire oval)? Thank you.
- circuitikz: How to use circuitikz inside a TikZ-matrixby cis on December 30, 2025 at 11:27 am
Is it possible to use circuitikz-shapes as cells inside a TikZ-matrix? (I mean, as cells <*> & <*> & <*> ... \\, how to place nodes afterwards is already clear.) If I put in |[tgenericshape]|{} I get an error ! Package PGF Math Error: Unknown function base (in 'base'). \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage{circuitikz} \usetikzlibrary{matrix} \begin{document} \begin{circuitikz}[] \node[tgenericshape, label=center:GS0](G0){}; \matrix[matrix of nodes, nodes in empty cells, draw, column sep=11mm, ] at (0,-2) (m){ 1 & 2 & 3 \\ %|[tgenericshape, label=center:GS1]|{} & |[fill=pink]|{Test} & \\ does not work }; \end{circuitikz} \end{document}
- circuitikz: How to read out the value of bipoles/lengthby cis on December 30, 2025 at 8:55 am
According to the manual, section 3.1.4.1 "Components size", bipoles/length (default 1.4cm) is the central parameter; "which can be interpreted as the length of a resistor (including reasonable connections): all other lengths are relative to this value." How can I read out bipoles/length? I tried \pgfmathsetlengthmacro\Rlength{ %\ctikzvalueof{bipoles/length}% does not work %\pgfkeysvalueof{/tikz/circuitikz/bipoles/length}% does not work 5mm% works } without success. What do I have to do? \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage{circuitikz} \begin{document} \pgfmathsetlengthmacro\Rlength{ %\ctikzvalueof{bipoles/length}% does not work %\pgfkeysvalueof{/tikz/circuitikz/bipoles/length}% does not work 5mm% works } \begin{circuitikz}[european resistors] \draw[] (0,0) to[R, name=R0] (2,0); \draw[red] (R0.west) -- +(\Rlength,0) node[below=3mm]{\Rlength}; \end{circuitikz} \ctikzset{bipoles/length=22.5mm,}% test for value change \begin{circuitikz}[european resistors] \draw[] (0,0) to[R, name=R0] (2,0); \draw[red] (R0.west) -- +(\Rlength,0) node[below=3mm]{\Rlength}; \end{circuitikz} \end{document}
- How can I place a mercator map on an overlay tikzpicture?by TobiBS on December 29, 2025 at 9:54 pm
I want to precisely place a mercatormap on my page and hence use the remember picture,overlay options. But I find no way to e.g. put the top left corner of my map to the center of the page. Here is my MWE: \def\mrcpkgprefix{} \documentclass{scrartcl} \usepackage{mercatormap} \begin{document} \begin{tikzpicture}[remember picture, overlay] \node at (current page.center) {E.g. left Corner of the map here?}; \mrcdefinemap{west=9.1,east=9.45,south=48.7,north=48.95,tile size=1cm,zoom=14} \path[draw,fill=green!10] (mrcmap.south west) rectangle (mrcmap.north east); \mrcdrawnetwork \coordinate (Stuttgart) at (mrcq cs:48.775556:9.182778); \node at (Stuttgart) {Stuttgart}; \end{tikzpicture} \end{document} Any idea which option or trick can help to do what I want to achieve?
- circuitikz: European Amplifier (en amp) without pins or with absolut valued pin lengthby cis on December 29, 2025 at 12:10 pm
I want to create an en amp with a pin length of 0 - alternatively: a pin length with a clearly defined value, for example 5mm. I tried to transfer the "trick" \ctikzset{tripoles/en amp/port width=1, tripoles/en amp/width=1.19, % = 1.7*0.7 } from 4.20.2.2 "Input and output pins symbols"; but this only works with op amp. What do I have to do? \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage{circuitikz} \begin{document} \begin{circuitikz}[] \ctikzset{tripoles/en amp/port width=1, tripoles/en amp/width=1.19, % = 1.7*0.7 } \node[en amp, en amp text={No pins}, label={[yshift=-12mm]below:works not} ] (A){please!}; %% --> Trick from 4.20.2.2 "Input and output pins symbols" \ctikzset{tripoles/op amp/port width=1, tripoles/op amp/width=1.19, % 1.7*0.7 } \draw (3,0) node[op amp, color=blue, label={[yshift=-12mm]below:works} ]{}; \end{circuitikz} \end{document}
- DNA helix and chromosome symbols built in tikz-pgfby Sebastiano on December 27, 2025 at 10:22 pm
I'm wondering if there are predefined symbols chromosomes-dna in pdfLaTeX or done in TikZ similar to those used in biology textbooks. Here two examples: What libraries can I use to create the envelope curves in blue for the "X"? (For the 2-nd figure, credit from wikipedia https://en.wikipedia.org/wiki/Chromosome#/media/File:Chromosome.svg)
- How to format the node's position center with different width in forest package?by Explorer on December 27, 2025 at 4:56 pm
With the following code: \documentclass[border=5pt]{standalone} \usepackage[edges]{forest} \usetikzlibrary{arrows.meta,shapes,shadows,trees} \tikzset{ basic/.style = { draw, drop shadow, rectangle, text width=2cm, font=\sffamily }, root/.style = { basic, thin, rounded corners=2pt, align=center, fill=green!30, }, onode/.style = { basic, thin, rounded corners=2pt, align=center, fill=green!60,text width=3cm, }, tnode/.style = { basic, thin, align=left, fill=pink!60, text width=6.5em, }, xnode/.style = { basic, thin, rounded corners=2pt, align=center, fill=blue!20,text width=5cm, }, wnode/.style = { basic, thin, fill=pink!10!blue!80!red!10, align=left, text width=6.5em, }, } \begin{document} \begin{forest} for tree={ grow=east, forked edge, parent anchor=east, child anchor=west, where n children=0{tier=word}{}, }, [Networked Game Work BreakDown, root, [Software Engineering Report, xnode [Setting shape, tnode] [Choosing color, tnode] [Adding shading, tnode] ] [Game Demo Preparation, onode [Using a Matrix, tnode] [Relatively, tnode] [Absolutely, tnode] [Using overlays, wnode] ] [Project Proposal and Game Logic, onode [Default arrows, tnode] [Arrow library, tnode] [Resizing tips, tnode] [Shortening, tnode] [Bending, tnode] ] ] \end{forest} \end{document} Which gives: However, it looks not so good, with two green nodes NOT aligned in the center of the edge, for the sake of different width in the same level. Is that possible to tweak the intersection shift right and aligned with the third sub-trees?
- How to tune the forest with recombining node elegantly?by Explorer on December 27, 2025 at 3:20 am
My question is similar to: https://tex.stackexchange.com/a/737502/322482 https://tex.stackexchange.com/a/593979/322482 https://tex.stackexchange.com/a/588156/322482 However, with different node width and hard position control, I don't think they are exactly the same as mine. \documentclass[border=5pt]{standalone} \usepackage{libertine} \usepackage{amsmath} \usepackage{forest} \usetikzlibrary{arrows.meta} \begin{document} \begin{forest} for tree={ draw,l sep=1cm, minimum width=2cm, minimum height=8ex, anchor=center, align=center, edge={-Stealth,thick}, if n=1{ edge label={node[midway,left=3pt,font=\scriptsize]{no}}, }{ edge label={node[midway,right=3pt,font=\scriptsize]{yes}}, } }, where level<=2{fill=green!30}{fill=magenta!50,minimum height=10ex,minimum width=1cm}, [Is $\mathbf{A}$ Hermitian? [Is $\mathbf{A^*v}$ available? [Is storage\\ expensive? [GMRES] [CGS\\Bi-CGSTAB\\GMRES($l$),] ] [Is $\mathbf{A}$ well-\\conditioned? [QMR\\BiCG] [CGN,phantom]%<-??? ] ] [Is $\mathbf{A}$ definite? [Is $\mathbf{A}$ well-\\conditioned? [CGN] [MINRES\\{\large or other}] ] [Are largest and smallest\\ eigenvalues known? [CG] [CG with\\ Chebyshev] ] ] ] \end{forest} \end{document} Noted that it produce: As the figure shows, I also want it to share the same node——"CGN", and move it a little bit left, however, I don't know how to change the horizinal distance to make them overlap(because the width of the leaf nodes are not the same), or any more elegant method is welcome! In a word, the "combining node" has two issues: How to tune the position horizonally? How to temporarily change if n=1{edge label={node[midway,left=3pt,font=\scriptsize]{no}},}{edge label={node[midway,right=3pt,font=\scriptsize]{yes}}} in my framework now? I want to make good uses of forest's feature to achieve the seperation of content and style. The original figure I want to replicate is(not to be exactly the same,just similar is okay):
- Epicycle and deferent of the Ptolemaic modelby Sebastiano on December 26, 2025 at 2:22 pm
About 15 years ago, I had created a drawing using GeoGebra that looks similar to the attached image. The source .ggb file from GeoGebra is available here, and I'm happy to share it with anyone interested. I was wondering if it's possible to replicate this drawing exactly using TikZ-PGF. I have the .ggb file and I'm wondering if there's a way to convert it or if TikZ can reproduce the same graphic. Additionally, I found a more recent package, named pst-sphericaltrochoid, which might be useful for generating spherical trochoid curves, and the package is documented in the PDF manual from December 25, 2025. Moreover, I would like to have this drawing animated in LaTeX. When export in tikz-pgf using Geogebra the output is not the expected result like the image (with animations). I never done a drawing with animate package or similar. \documentclass[10pt]{article} \usepackage{pgfplots} \pgfplotsset{compat=1.15} \usepackage{mathrsfs} \usetikzlibrary{arrows} \pagestyle{empty} \begin{document} \definecolor{ffwwqq}{rgb}{1,0.4,0} \definecolor{zzttqq}{rgb}{0.6,0.2,0} \definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1} \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm] \begin{axis}[ x=1cm,y=1cm, axis lines=middle, grid style=dashed, xmin=-24.649425971185988, xmax=51.05123247996474, ymin=-17.77843276444837, ymax=20.90166759086156, xtick={-20,-15,...,50}, ytick={-15,-10,...,20},] \clip(-24.649425971185988,-17.77843276444837) rectangle (51.05123247996474,20.90166759086156); \draw [line width=0.8pt] (0,0) circle (8cm); \draw [line width=0.8pt] (4.690951292494638,6.480353074597315) circle (2cm); \draw[line width=4pt] (-22.73456951795283,17.710240168806287) -- (-9.968859829731798,17.710240168806287); \draw[line width=4pt] (-22.73456951795283,15.157098231162069) -- (-9.968859829731798,15.157098231162069); \begin{scriptsize} \draw [fill=xdxdff] (4.690951292494638,6.480353074597315) circle (0.5pt); \draw[color=xdxdff] (4.137249375752443,7.338101047126645) node {$A$}; \draw [fill=black] (-17.202761986390385,17.710240168806287) circle (2.5pt); \draw[color=black] (-16.096400480077897,19.40169670249558) node {$k = 1.3$}; \draw [fill=zzttqq] (2.345168103332513,5.359058630909856) circle (1pt); \draw[color=zzttqq] (4.392563569516864,6.316844272068956) node {$Pianeta$}; \draw [fill=black] (-17.06092076763237,15.157098231162069) circle (2.5pt); \draw[color=black] (-16.479371770724526,16.848554764851364) node {$v = 5$}; \draw [color=ffwwqq] (0,0) circle (4.5pt); \draw[color=ffwwqq] (1.264964695902711,1.4658745905449386) node {$Sole$}; \end{scriptsize} \end{axis} \end{tikzpicture} \end{document} My idea is to animate the drawing using the animate package for my students of an high school, with the ability to modify parameters and see how the drawing changes in real time. Could I add interactive buttons to allow users to modify the parameters of the animation? If anyone has experience animating drawings in LaTeX, I'd be happy to receive suggestions on how to implement it. Also, how can I animate package this drawing and add interactive buttons to control the parameters?
- Precision issue with Tikz tangent coordinate systemby I. Cho on December 25, 2025 at 12:21 pm
The TikZ tangent coordinate system appears to be inaccurate. The blue and red lines are expected to overlap, but they fail to do so. \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \draw [help lines,dotted,thick] (0,0) grid (10,10); \def\rA{.5} \def\rB{4} \coordinate (OA) at (1,1); \coordinate (OB) at (5,5); \path (OA) node (A) [draw,circle,minimum size=2*\rA cm] {A}; \path (OB) node (B) [draw,circle,minimum size=2*\rB cm] {B}; \path ($(A.center)!{\rA/(\rA - \rB)}!(B.center)$) coordinate (X) node [below left] {X}; \path (tangent cs:node=A,point={(X)},solution=1) coordinate (A1); \path (tangent cs:node=A,point={(X)},solution=2) coordinate (A2); \path (tangent cs:node=B,point={(X)},solution=1) coordinate (B1); \path (tangent cs:node=B,point={(X)},solution=2) coordinate (B2); \draw [blue] (X) -- (A1) -- ([turn]0:9cm); \draw [red] (X) -- (B1) -- ([turn]0:5cm); \draw [blue] (X) -- (A2) -- ([turn]0:9cm); \draw [red] (X) -- (B2) -- ([turn]0:5cm); \end{tikzpicture} \end{document} Corrected by adding outer sep=0pt: \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \draw [help lines,dotted,thick] (0,0) grid (10,10); \def\rA{.5} \def\rB{4} \coordinate (OA) at (1,1); \coordinate (OB) at (5,5); \path (OA) node (A) [draw,circle,minimum size=2*\rA cm,outer sep=0pt] {A}; %% \path (OB) node (B) [draw,circle,minimum size=2*\rB cm,outer sep=0pt] {B}; %% \path ($(A.center)!{\rA/(\rA - \rB)}!(B.center)$) coordinate (X) node [below left] {X}; \path (tangent cs:node=A,point={(X)},solution=1) coordinate (A1); \path (tangent cs:node=A,point={(X)},solution=2) coordinate (A2); \path (tangent cs:node=B,point={(X)},solution=1) coordinate (B1); \path (tangent cs:node=B,point={(X)},solution=2) coordinate (B2); \draw [blue] (X) -- (A1) -- ([turn]0:9cm); \draw [red] (X) -- (B1) -- ([turn]0:5cm); \draw [blue] (X) -- (A2) -- ([turn]0:9cm); \draw [red] (X) -- (B2) -- ([turn]0:5cm); \end{tikzpicture} \end{document}
- nicematrix, \CodeAfter and overlappingby projetmbc on December 25, 2025 at 11:11 am
Is there an automatic way to avoid "TikZ code after" overlap the text? I give a real use case, and not a MWE. \documentclass[12pt]{scrartcl} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[top=1cm, bottom=1.95cm, left=.9cm, right=.9cm]{geometry} \usepackage{nicematrix} \usepackage[svgnames]{xcolor} \usepackage{tikz] \tikzset{ product/.style = { shorten > = 3.75mm, thick }, product-times/.style = { pos=0.5, circle, fill=white, inner sep=2pt }, arrow/.style = { ->, thick }, rounded-frame/.style = { draw, rounded corners, thick, inner sep = 5pt, anchor = west } } \begin{document} XXX $\begin{NiceArray}{*{9}{c}}[cell-space-limits=3pt] & & & & & & & & C_j^{\,\prime} \\ & & & & & & & & \phantom{X} \\ & & & & & & & & \Vdots[shorten-start=11pt] \\ & & & & & & & & \color{IndianRed}a[k]_{qj} \\ & & & & & & & & \Vdots \\ & & & & & & & & \color{ForestGreen} a[k]_{rj} \\ & & & & & & & & \Vdots[shorten-end=21pt] \\ & & \NotEmpty & & & & \NotEmpty & & \\ L_i & \hspace{3pt} & \Cdots[shorten-start=18pt] & \color{IndianRed} 1 & \Cdots & \color{ForestGreen} 0 & \Cdots[shorten-end=18pt] & \hspace{12.5pt} & a[k{+}1]_{ij} % \CodeAfter % Sous-matrices. \SubMatrix({3-9}{7-9})[slim] \SubMatrix({9-3}{9-7}) \SubMatrix({9-9}{9-9}) % Décorons... \begin{tikzpicture} % Indication pour la ligne et la colonne. \draw[ arrow, shorten > = 8mm, ] (1-9.south) to (4-9.north); \draw[ arrow, shorten < = 1mm, shorten > = 9.5mm, ] (9-1.east) to (9-4.west); % Flèches des produits. \draw[ product, IndianRed, ] (9-4.north) to [bend left] node[ product-times, draw = IndianRed, ] {$\times$} (4-9.west); \draw[ product, ForestGreen, ] (9-6.north) to [bend left] node[ product-times, draw = ForestGreen ] {$\times$} (6-9.west) ; % Signification des entrées. \draw[ arrow, ForestGreen, ] ([yshift=-5mm]9-6.south) to (9-6.south); \node[ rounded-frame, ForestGreen ] at ([yshift=-8.1mm, xshift=-2mm]9-6.south) {Pas de lien direct de $i$ à $r$.}; % \draw[ arrow, IndianRed, ] ([yshift=-13.5mm]9-4.south) to (9-4.south); \node[ rounded-frame, IndianRed ] at ([yshift=-17mm, xshift=-2mm]9-4.south) {Un lien direct de $i$ à $q$.}; % \draw[ arrow, IndianRed ] ([xshift=8.5mm] 4-9.east) to ([xshift=3.5mm] 4-9.east); \node[ rounded-frame, IndianRed, ] at ([xshift=8.5mm] 4-9.east) {Nombre de parcours de longueur $k$ de $q$ à $j$.}; % \draw[ arrow, ForestGreen, ] ([xshift=8.5mm] 6-9.east) to ([xshift=3.5mm] 6-9.east); \node[ rounded-frame, ForestGreen, ] at ([xshift=8.5mm] 6-9.east) {Nombre de parcours de longueur $k$ de $r$ à $j$.}; \end{tikzpicture} \end{NiceArray}$ XXX \end{document}
- Commutative diagrams using square boxesby ncant on December 23, 2025 at 3:38 pm
I would like to reproduce the following commutative diagram, consisting of square boxes with mathematical expressions located near the corners, rather than mathematical expressions connected by an arrow. Since this type of diagram only develops vertically, as if it's a single column, I think it is possible to create a command that uses TikZ to draw a square and accepts four arguments, one for each edge of the square. However, I am having difficulty stacking these squares. Can you help me? Thank you EDIT: These are the instructions I'm using for making the square box. These are normally located inside a command that takes four argument, one for each corner. \begin{tikzpicture} \draw[thick] (0,0) rectangle (2,2); \node[left] at (0,2) {$f(t)$}; \node[left] at (0,0) {$e^{at}f(t)$}; \node[right] at (2,2) {$F(s)$}; \node[right] at (2,0) {$F(s-a)$}; \end{tikzpicture} These result in the following figure:
- angle condition judge error in tikz?by Explorer on December 23, 2025 at 2:01 pm
I have the following code to plot the "outer" semicircle: \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{calc} % https://tex.stackexchange.com/a/666441/322482 \newcommand*\drawSemicircle[3][]{% \coordinate (mid) at ($(#2)!0.5!(#3)$); \draw[#1] (#2) let \p{A} = ($(#2)-(mid)$), \p{B} = ($(#3)-(mid)$), \n{cross} = {\x{A}*\y{B} - \y{A}*\x{B}}, \n{angA} = {atan2(\y{A},\x{A})}, \n{angB} = {atan2(\y{B},\x{B})}, \n{R} = {veclen(\x{A},\y{A})}, \n{start} = {(\n{cross}>0 ? \n{angA} : \n{angB})}, \n{endraw} = {(\n{cross}>0 ? \n{angB} : \n{angA})}, \n{end} = {(\n{endraw} < \n{start} ? \n{endraw} + 360 : \n{endraw})} in arc[start angle=\n{start},end angle=\n{end},radius=\n{R}]; } \begin{document} \begin{tikzpicture} \foreach \x in {1,...,60}{ \node[circle,draw=magenta,thick] (in-\x) at ({\x*6}:5cm) {}; \node[circle,draw=teal,thick] (out-\x) at ({\x*6}:5.5cm) {}; } \foreach \pstart[evaluate=\pstart as \pend using {int(mod(\pstart+9,60)+1)}] in {1,...,60}{ \drawSemicircle[semithick]{in-\pstart}{out-\pend} % \node[fill=white,circle,label={[label distance=-2em,text=magenta]\pstart*6:\pstart}] at (in-\pstart) {};%<-not elegant here % \node[fill=white,circle,label={[label distance=+1em,text=teal]\pstart*6:\pstart}] at (out-\pend) {}; } \end{tikzpicture} \end{document} Which gives: However, when I substitute: \node[circle,draw=teal,thick] (out-\x) at ({\x*6}:5.5cm) {}; with \node[circle,draw=teal,thick] (out-\x) at ({\x*6}:6cm) {}; Things broken, I guess that it's something like angle float error.... But I don't know how to fix this:
- Tikz to plot a part of a coneby Latexfan on December 23, 2025 at 10:30 am
I try to use tikz to plot the following image ... \documentclass[border=0.2cm]{standalone} \usepackage{pgfplots} \usepgfplotslibrary{colormaps} \pgfplotsset{compat = newest} \begin{document} \begin{tikzpicture} \begin{axis}[ axis equal image, grid = both, minor tick num = 2, xlabel = {$x$}, ylabel = {$y$}, zlabel = {$z$}, major grid style = {draw = lightgray}, minor grid style = {draw = lightgray!25}, xmin = 0, xmax = 1, ymin = 0, ymax = 1, zmin = 0, zmax = 2, scale = 3, view = {60}{30}, samples = 30, samples y = 30, z buffer = sort, ] % Kjeglesektor \addplot3[ surf, shader = interp, opacity = 0.75, colormap/viridis, ] ({x},{y},{sqrt(3)*sqrt(x^2+y^2)}); \end{axis} \end{tikzpicture} \end{document} But I do not get similar image ... can you please help me?
- Custom 3D line plot in plain tikz and/or luadrawby Dr. Manuel Kuehner on December 19, 2025 at 12:30 pm
Disclaimer This question is a bit of "do it for me" but there is a histrory behind it, see this question. User Jasper offered me a solution without using pgfplots. I plan to add a bounty as soon as it is possible. Question I want to create diagram with a 3D line plots. The main feature is to have several x axes that share the same y axis. Each x axis has its own F (or z) axis. There are only data points on specific y values (in the example below at +30, +15, 0, -15). In addition, the y axis is reversed (+ and - direction reversed). I need a grid in each F-x plane. Important ist also, that all F axes share the same min and max. Each axis should have a label and the diagram should have a title. The data is given in separate csv files, see example below. The MWE contains the data and plots the data (for testing) using pgfplots. Goal: The goal is to have a plain tikz solution and maybe in addition, a solution based on luadraw or lua-tikz3dtools respectively. I am looking for a easy-to-use custom interface for my plot task. If the result looks as it is created with pgfplots, then I am happy. S!#i, I forgot a key feature (not shown in the hand drawing) In addition to the x-F plots described above, there is ONE plot in the y-F plane (= from left to right). This works, because all F axes share the same min and max. \begin{filecontents*}{y_F_data.csv} y,F -15,20 -14,8 30,-4 \end{filecontents*} \documentclass{article} \usepackage{pgfplots} % ------------------------------- \begin{filecontents*}{x_zero.csv} x,F -30,12 -29,8 30,-4 \end{filecontents*} \begin{filecontents*}{x_neg_one.csv} x,F -30,12 -29,8 30,-4 \end{filecontents*} \begin{filecontents*}{x_pos_one.csv} x,F -30,12 -29,8 30,-4 \end{filecontents*} \begin{filecontents*}{x_pos_two.csv} x,F -30,12 -29,8 30,-4 \end{filecontents*} % ------------------------------- \begin{document} \begin{tikzpicture} \begin{axis}[ axis lines = center, title = {$x_0$}, xlabel = {$x_0$}, ylabel = {$F_0$}, xmin = -30, xmax = 30, ymin = -100, ymax = 100, ] \addplot table [x=x, y=F, col sep = comma] {x_zero.csv}; \end{axis} \end{tikzpicture} \begin{tikzpicture} \begin{axis}[ axis lines = center, title = {$x_{-1}$}, xlabel = {$x_{-1}$}, ylabel = {$F_{-1}$}, xmin = -30, xmax = 30, ymin = -100, ymax = 100, ] \addplot table [x=x, y=F, col sep = comma] {x_neg_one.csv}; \end{axis} \end{tikzpicture} \begin{tikzpicture} \begin{axis}[ axis lines = center, title = {$x_{1}$}, xlabel = {$x_{1}$}, ylabel = {$F_{1}$}, xmin = -30, xmax = 30, ymin = -100, ymax = 100, ] \addplot table [x=x, y=F, col sep = comma] {x_pos_one.csv}; \end{axis} \end{tikzpicture} \begin{tikzpicture} \begin{axis}[ axis lines = center, title = {$x_{2}$}, xlabel = {$x_{2}$}, ylabel = {$F_{2}$}, xmin = -30, xmax = 30, ymin = -100, ymax = 100, ] \addplot table [x=x, y=F, col sep = comma] {x_pos_two.csv}; \end{axis} \end{tikzpicture} \end{document}
- How to draw a complete graph $K_5$ with 5 edges with different colors and the vertices are not big filled circles?by Intuition on December 12, 2025 at 10:17 pm
I am trying to draw a complete graph $K_5$ with 5 edges with different colors and the vertices are not big filled circles? I found this here A complete graph on 5 vertices with coloured edges but I do not know how to have 5 edges with different colors and the vertices are not big filled circles, just small filled circles. Any hints will be greatly appreciated. I also do not want this one here How to draw the following graph in latex? , I want the edges themselves to be of different colors not shaded by different colors.
- I would like to discretize the "tiles" into rectangular prismatic groups, sort each group, then sort the groups by each other or be shown a better wayby Jasper on December 4, 2025 at 7:58 am
I have built a comparator which can determine the occlusive relationship between two 0--2-dimensioal affine tiles (using their simplicial representations). In English, if I have two tiles (a tile is a point, line segment, or triangle), I can determining which one occludes the other, or if there is no occlusion (the inconclusive case). Currently, this requires an extremely expensive SCC topological sort (quadratic based on the number of tiles). I have the idea that I would like to speed this up, and I have a proposal for doing so (though, I am all ears to alternative ideas too). Basically, my idea is to partition the scene into rectangular prismatic regions (possibly with some overlap), sorting each one individually. Then, each rectangular prismatic region could use a waaay simpler sorting method on the set of rectangular prismatic region, once their constituent parts are sorted. This is my AI generated SCC topological sort routine, which has been working for ages. I am confident in it, based on it having not failed yet. How could I go about implementing this without visual artefacts from tiles which cross the boundary of two or more prisms? Alternatively, what better methods might I consider which I haven't yet? -- occlusion graph + SCC topo sort (bboxes computed on Cartesian coords) local n = #items local bboxes, graph = {}, {} for i = 1, n do bboxes[i] = { get_bbox2(items[i]) }; graph[i] = {} end for i = 1, n - 1 do for j = i + 1, n do if bboxes_overlap2(bboxes[i], bboxes[j]) then local r = cmp(items[i], items[j]) if r == true then table.insert(graph[i], j) elseif r == false then table.insert(graph[j], i) end end end end local index, stack, indices, lowlink, onstack, sccs = 0, {}, {}, {}, {}, {} for i = 1, n do indices[i], lowlink[i] = -1, -1 end local function dfs(v) indices[v], lowlink[v] = index, index; index = index + 1 stack[#stack+1] = v; onstack[v] = true for _, w in ipairs(graph[v]) do if indices[w] == -1 then dfs(w); lowlink[v] = math.min(lowlink[v], lowlink[w]) elseif onstack[w] then lowlink[v] = math.min(lowlink[v], indices[w]) end end if lowlink[v] == indices[v] then local scc = {} while true do local w = table.remove(stack); onstack[w] = false scc[#scc+1] = w if w == v then break end end sccs[#sccs+1] = scc end end for v = 1, n do if indices[v] == -1 then dfs(v) end end local scc_index, scc_graph, indeg = {}, {}, {} for i, comp in ipairs(sccs) do for _, v in ipairs(comp) do scc_index[v] = i end scc_graph[i], indeg[i] = {}, 0 end for v = 1, n do for _, w in ipairs(graph[v]) do local si, sj = scc_index[v], scc_index[w] if si ~= sj then table.insert(scc_graph[si], sj); indeg[sj] = indeg[sj] + 1 end end end local queue, sorted = {}, {} for i = 1, #sccs do if indeg[i] == 0 then queue[#queue+1] = i end end while #queue > 0 do local i = table.remove(queue, 1) for _, v in ipairs(sccs[i]) do sorted[#sorted+1] = items[v] end for _, j in ipairs(scc_graph[i]) do indeg[j] = indeg[j] - 1 if indeg[j] == 0 then queue[#queue+1] = j end end end In fact, I would also like to employ a similar strategy for partitioning, since it is also quadratic, but I think that if I saw it for occlusion, that it would be simple to re-implement for partitioning. This MWE, for example, takes ages to compile, and I believe it should be speed-up-able. This version is currently on TeXLive and MikTeX (and on CTAN), so there is no need to use the GitHub version. \documentclass[tikz,border=1cm]{standalone} \usepackage{lua-tikz3dtools} % https://github.com/Pseudonym321/TikZ-Animations/tree/master1/TikZ/lua-tikz3dtools \begin{document} \begin{luatikztdtoolspicture}[ C1 = { {{-3,-3,0,1}} } ,C2 = { {{3,3,-10,1}} } ,light = { {{0,0,-2,1}} } ] \pgfmathsetmacro{\param}{0} \setobject[ name = {T} ,object = { matrix_multiply( matrix_multiply( euler(pi/2,pi/4+pi/4*sin(\param),5.25*pi/6+\param) ,translate(0,0,-5) ) ,matrix_multiply( { {1,0,0,0} ,{0,1,0,0} ,{0,0,1,0} ,{0,0,0,1} } ,matrix_multiply(xscale(1/2),yscale(1/2)) ) ) } ] \setobject[ name = {I} ,object = { matrix_inverse(T) } ] \appendsurface[ ustart = {-2} ,ustop = {2} ,usamples = {20} ,vstart = {-2} ,vstop = {2} ,vsamples = {20} ,transformation = {T} ,x = {u} ,y = {v} ,z = {u^4 + v^4 - 4*u*v + 1} ,fill options = { preaction = { fill = green ,fill opacity = 0.2 } ,postaction = { draw = blue ,ultra thin ,line join = round } } ,filter = { abs(matrix_multiply(A,I)[1][3])<2.01 and abs(matrix_multiply(B,I)[1][3])<2.01 and abs(matrix_multiply(C,I)[1][3])<2.01 and abs(matrix_multiply(A,I)[1][2])<2.01 and abs(matrix_multiply(B,I)[1][2])<2.01 and abs(matrix_multiply(C,I)[1][2])<2.01 and abs(matrix_multiply(A,I)[1][1])<2.01 and abs(matrix_multiply(B,I)[1][1])<2.01 and abs(matrix_multiply(C,I)[1][1])<2.01 } ] \appendsolid[ ustart = {-2} ,ustop = {2} ,usamples = {2} ,vstart = {-2} ,vstop = {2} ,vsamples = {2} ,wstart = {-2} ,wstop = {2} ,wsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {w} ,fill options = { preaction = { fill = none ,fill opacity = 0.5 } ,postaction = { draw = none ,ultra thin ,line join = round ,line cap = round } } ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {0} ,y = {0} ,z = {u} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {0} ,y = {0} ,z = {4.3} ,transformation = {T} ,name = {\(z\)} ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {0} ,y = {u} ,z = {0} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {0} ,y = {4.3} ,z = {0} ,transformation = {T} ,name = {\(y\)} ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {u} ,y = {0} ,z = {0} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {4.3} ,y = {0} ,z = {0} ,transformation = {T} ,name = {\(x\)} ] \foreach \p in {-4,-3,...,4} { \appendcurve[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,x = {u} ,y = {\p} ,z = {0} ,transformation = {T} ,draw options = { draw = black!70!white ,ultra thin ,line cap = round ,densely dashed } ] \appendcurve[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,x = {\p} ,y = {u} ,z = {0} ,transformation = {T} ,draw options = { draw = black!90!white ,ultra thin ,line cap = round ,densely dashed } ] } \appendsurface[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,vstart = {-4} ,vstop = {4} ,vsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {0} ,fill options = { preaction = { fill = gray!70!white ,fill opacity = 0.6 } ,postaction = { draw = none ,ultra thin ,line join = round } } ] \end{luatikztdtoolspicture} \end{document}
- tikz node fill to highlight text causes extra line below text (used in tblr)by bennynihon on November 29, 2025 at 5:58 am
When I use the text highlighting tikz command, as shared here, it adds an extra line or vertical spacing below it. In my case I'm using it in a two column nested tblr. You can see if the tikz highlight is replaced with a simple bold text, it works as expected with no extra vertical space. I thought it was the size of the highlight creating the issue, so I tried an 'inner sep=1pt' in the tikz command, but it still results in the extra space. How can I avoid this extra space below? Thank you. \documentclass{article} \usepackage{tabularray} \usepackage{tikz} \definecolor{mblue}{HTML}{2a66ad} \newcommand{\hlitet}[2][mblue]{% \hspace{0pt}{% \tikz[baseline=(N.base)]\node[fill=#1,rounded corners](N){#2}; }% \hspace{-2pt}% } % using hlines and vlines to show the effect \NewDocumentCommand{\fsmtx}{mm}{% \begin{tblr}{colspec={@{}X[l,-1]@{\hspace{4pt}}X[l]@{}},baseline={T},hlines,vlines}% {\hlitet[mblue]{\textcolor{white}{#1}}} & {#2}% \end{tblr}% } \NewDocumentCommand{\fsmtxb}{mm}{% \begin{tblr}{colspec={@{}X[l,-1]@{\hspace{4pt}}X[l]@{}},baseline={T},hlines,vlines}% {\textcolor{mblue}{\textbf{#1.}}} & {#2}% \end{tblr}% } \begin{document} \begin{longtblr}{ colspec={X[l,-1]X[l,-1]}, rowhead=1, hlines,vlines } {State} & {Transitions} \\ {StateA} & \fsmtx{a}{this is a test of a single line description} \fsmtx{b}{this is a test of a multi line description, as this will occupy a second line} \\ {StateB} & \fsmtxb{a}{this is a test of a single line description} \fsmtxb{b}{this is a test of a multi line description, as this will occupy a second line} \end{longtblr} \end{document} Update: swapping the \hlitet with this tcbox solution below, seems to work well. But I am curious as to why the tikz solution causes the additional vertical spacing. \newcommand\hliteb[2][mblue]{\tcbox[on line, colback=#1, colframe=#1, boxsep=0pt, top=3pt, bottom=3pt, left=3pt, right=3pt, boxrule=0pt]{#2}}
- There is a problem for triangles which are capable of partitioning eachother, which also coincide at one vertex. I am having trouble debugging itby Jasper on November 21, 2025 at 5:45 am
NOTE: I revised my formulation of the problem, and posted it on SO where it might have a better chance of reaching the right people. It can be found here, https://stackoverflow.com/q/79829288/29000697. I am writing a software which is supposed to take a set of triangles, where some of the members of the set are capable of partitioning one another, and performing all possible partitioning. I built Lua functions which are capable of detecting and performing most intersections. Unfortunately, there appears to be a particular case which is causing me some trouble. For example, consider the following diagram where I deliberately used a complicated case to show that my algorithm works in most cases. [Unfortunately, you need to run the GitHub version of the package :-(. This is because I want to fix this bug and write new documentation before making another release.] \documentclass[tikz,border=1cm]{standalone} \usepackage{lua-tikz3dtools} % https://github.com/Pseudonym321/TikZ-Animations/tree/master1/TikZ/lua-tikz3dtools \begin{document} \pgfmathsetmacro{\i}{-pi/4} \begin{tikzpicture} \useasboundingbox[scale=2] (-1,-1) rectangle (1,1); \setobject[ name = {T} ,object = { matrix_multiply( matrix_multiply( euler(pi/2,pi/3,7*pi/6) ,translate(0,0,-5) ) ,matrix_multiply( { {1,0,0,0} ,{0,1,0,0} ,{0,0,1,0} ,{0,0,0,1} } ,matrix_multiply(xscale(1),yscale(1)) ) ) } ] \setobject[ name = {I} ,object = { matrix_inverse(T) } ] \foreach \j in {2,3,1,0}{ \appendsurface[ ustart = {-2} ,ustop = {2} ,usamples = {2} ,vstart = {-2} ,vstop = {2} ,vsamples = {2} ,transformation = {matrix_multiply(euler(\j+\i,2*\j,\j),T)} ,x = {u} ,y = {v} ,z = {\j/10} ,fill options = { preaction = { \ifnum\j=0 fill = red \fi \ifnum\j=2 fill = green \fi \ifnum\j=1 fill = yellow \fi \ifnum\j=3 fill = blue \fi ,fill opacity = 0.6 } ,postaction = { draw = black ,ultra thin ,line join = round ,line cap = round } } ,filter = { abs(matrix_multiply(A,I)[1][3])<1.01 and abs(matrix_multiply(B,I)[1][3])<1.01 and abs(matrix_multiply(C,I)[1][3])<1.01 and abs(matrix_multiply(A,I)[1][2])<1.01 and abs(matrix_multiply(B,I)[1][2])<1.01 and abs(matrix_multiply(C,I)[1][2])<1.01 and abs(matrix_multiply(A,I)[1][1])<1.01 and abs(matrix_multiply(B,I)[1][1])<1.01 and abs(matrix_multiply(C,I)[1][1])<1.01 } ] } \appendsolid[ ustart = {-1} ,ustop = {1} ,usamples = {2} ,vstart = {-1} ,vstop = {1} ,vsamples = {2} ,wstart = {-1} ,wstop = {1} ,wsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {w} ,fill options = { preaction = { fill = gray ,fill opacity = 0.5 } ,postaction = { draw = black ,ultra thin ,line join = round ,line cap = round } } ] \displaysegments \end{tikzpicture} \end{document} Gif: This is a picture of four planes intersecting, clipped by a cube. Currently, for the clipping (filtering) to work, projective transformations currently do not work, only affine ones do. This will eventually be fixed, of course. So it works, and all is fine and well - why are we here? Well, in the above diagram, each plane is offset by a small (and in each case different) translation. If this translation weren't there (and even with it there sometimes), we are faced with two triangles, which are capable of partitioning one another, which are not partitioned. I have the sense (possibly wrong) that this case wherre partitioning fails is when two triangles are non-coplanar, and meet at a vertex with the rest of their bodies visually passing through each other. It appears that my functions are not detecting and/or are not partitioning this case. For example, without the translation (it's a small difference, look at the z key), we get the following horrible graphic. \documentclass[tikz,border=1cm]{standalone} \usepackage{lua-tikz3dtools} % https://github.com/Pseudonym321/TikZ-Animations/tree/master1/TikZ/lua-tikz3dtools \begin{document} \pgfmathsetmacro{\i}{-pi/4} \begin{tikzpicture} \useasboundingbox[scale=2] (-1,-1) rectangle (1,1); \setobject[ name = {T} ,object = { matrix_multiply( matrix_multiply( euler(pi/2,pi/3,7*pi/6) ,translate(0,0,-5) ) ,matrix_multiply( { {1,0,0,0} ,{0,1,0,0} ,{0,0,1,0} ,{0,0,0,1} } ,matrix_multiply(xscale(1),yscale(1)) ) ) } ] \setobject[ name = {I} ,object = { matrix_inverse(T) } ] \foreach \j in {2,3,1,0}{ \appendsurface[ ustart = {-2} ,ustop = {2} ,usamples = {2} ,vstart = {-2} ,vstop = {2} ,vsamples = {2} ,transformation = {matrix_multiply(euler(\j+\i,2*\j,\j),T)} ,x = {u} ,y = {v} ,z = {0} ,fill options = { preaction = { \ifnum\j=0 fill = red \fi \ifnum\j=2 fill = green \fi \ifnum\j=1 fill = yellow \fi \ifnum\j=3 fill = blue \fi ,fill opacity = 0.6 } ,postaction = { draw = black ,ultra thin ,line join = round ,line cap = round } } ,filter = { abs(matrix_multiply(A,I)[1][3])<1.01 and abs(matrix_multiply(B,I)[1][3])<1.01 and abs(matrix_multiply(C,I)[1][3])<1.01 and abs(matrix_multiply(A,I)[1][2])<1.01 and abs(matrix_multiply(B,I)[1][2])<1.01 and abs(matrix_multiply(C,I)[1][2])<1.01 and abs(matrix_multiply(A,I)[1][1])<1.01 and abs(matrix_multiply(B,I)[1][1])<1.01 and abs(matrix_multiply(C,I)[1][1])<1.01 } ] } \appendsolid[ ustart = {-1} ,ustop = {1} ,usamples = {2} ,vstart = {-1} ,vstop = {1} ,vsamples = {2} ,wstart = {-1} ,wstop = {1} ,wsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {w} ,fill options = { preaction = { fill = gray ,fill opacity = 0.5 } ,postaction = { draw = black ,ultra thin ,line join = round ,line cap = round } } ] \displaysegments \end{tikzpicture} \end{document} It appears that there is a problem for triangles which are capable of partitioning one another, which also coincide at a single vertex. I am having trouble debugging it. These are the main functions of the document which I am suspect of (it's a huge pipeline of interacting functions, all from the Lua file in the package, if you want to just go there): --- returns the partition of the first triangle into three subtriangles, --- if it intersects the second, otherwise produces nil --- @param T1 table<table<number>> the first triangle --- @param T2 table<table<number>> the second triangle --- @return table<table<table<number>>,table<table<number>>,table<table<number>>> table of sub triangles local function triangle_triangle_partition(T1, T2) local I = triangle_triangle_intersections(T1, T2) if I == nil then return nil end if #I == 0 then return nil end if #I == 1 then return nil end if #I ~= 2 then assert(false, ("I is not 2, it is instead: %f"):format(#I)) end local IO = I[1] local IU = vector_subtraction(I[2], IO) local I_basis = {IO[1], IU[1]} local T1A = {T1[1], T1[2]} local T1AU = vector_subtraction({T1A[2]}, {T1A[1]}) local T1A_basis = {T1A[1], T1AU[1]} local T1B = {T1[2], T1[3]} local T1BU = vector_subtraction({T1B[2]}, {T1B[1]}) local T1B_basis = {T1B[1], T1BU[1]} local T1C = {T1[3], T1[1]} local T1CU = vector_subtraction({T1C[2]}, {T1C[1]}) local T1C_basis = {T1C[1], T1CU[1]} local T2A = {T2[1], T2[2]} local T2AU = vector_subtraction({T2A[2]}, {T2A[1]}) local T2A_basis = {T2A[1], T2AU[1]} local T2B = {T2[2], T2[3]} local T2BU = vector_subtraction({T2B[2]}, {T2B[1]}) local T2B_basis = {T2B[1], T2BU[1]} local T2C = {T2[3], T2[1]} local T2CU = vector_subtraction({T2C[2]}, {T2C[1]}) local T2C_basis = {T2C[1], T2CU[1]} local points = {} local non_intersecting = nil local int1 = line_line_intersection(I_basis, T1A_basis) if int1 == nil then int1 = {solution = {}} end if #int1.solution ~= 0 then local t = int1.solution[1] local intersect = vector_addition( IO, scalar_multiplication(t, IU) ) if point_line_segment_intersecting(intersect, T1A) then table.insert(points, intersect) else non_intersecting = "T1A" end else non_intersecting = "T1A" end local int2 = line_line_intersection(I_basis, T1B_basis) if int2 == nil then int2 = {solution = {}} end if #int2.solution ~= 0 then local t = int2.solution[1] local intersect = vector_addition( IO, scalar_multiplication(t, IU) ) if point_line_segment_intersecting(intersect, T1B) then table.insert(points, intersect) else non_intersecting = "T1B" end else non_intersecting = "T1B" end local int3 = line_line_intersection(I_basis, T1C_basis) if int3 == nil then int3 = {solution = {}} end if #int3.solution ~= 0 then local t = int3.solution[1] local intersect = vector_addition( IO, scalar_multiplication(t, IU) ) if point_line_segment_intersecting(intersect, T1C) then table.insert(points, intersect) else non_intersecting = "T1C" end else non_intersecting = "T1C" end -- if #points == 3 then return nil end -- if #points == 1 then return nil end if #points ~= 2 then -- print("Partition failure: got", #points, "points") -- print("Triangle 1:", T1) -- print("Triangle 2:", T2) -- print("Non-intersecting edge:", non_intersecting) -- for i, p in ipairs(points) do -- print("Point", i, p[1][1], p[1][2], p[1][3]) -- end return nil --assert(false, "triangle_triangle_partition doesn't have exactly two points") end local quad = {} local tri1 local A, B = points[1], points[2] table.insert(quad, A[1]) table.insert(quad, B[1]) if non_intersecting == "T1A" then table.insert(quad, T1A[1]) table.insert(quad, T1A[2]) tri1 = {A[1], B[1], T1B[2]} elseif non_intersecting == "T1B" then table.insert(quad, T1B[1]) table.insert(quad, T1B[2]) tri1 = {A[1], B[1], T1C[2]} elseif non_intersecting == "T1C" then table.insert(quad, T1C[1]) table.insert(quad, T1C[2]) tri1 = {A[1], B[1], T1A[2]} end quad = centroid_sort(quad) return { tri1 = tri1, tri2 = {quad[1], quad[2], quad[3]}, tri3 = {quad[3], quad[4], quad[1]} } end --- produces exactly zero, or exactly two intersection points between two triangles --- @param T1 table<table<number>> a triangle defined by its vertices --- @param T2 table<table<number>> another triangle defined by its vertices --- @return table<table<number>> a matrix of exactly zero or exactly two points nothing else local function triangle_triangle_intersections(T1, T2) local edges1 = { {T1[1], T1[2]}, {T1[2], T1[3]}, {T1[3], T1[1]} } local edges2 = { {T2[1], T2[2]}, {T2[2], T2[3]}, {T2[3], T2[1]} } local points = {} --- appends a point to a list if it is unique --- @param P table<table<number>> a point local function add_unique(P) -- if not P then return nil end for _, Q in ipairs(points) do if point_point_intersecting(P, Q) then return nil end end table.insert(points, P) end -- Check all edge pairs for _, E1 in ipairs(edges1) do local intersect = line_segment_triangle_intersection(E1, T2) if intersect ~= nil then add_unique(intersect.intersection) end end for _, E2 in ipairs(edges2) do local intersect = line_segment_triangle_intersection(E2, T1) if intersect ~= nil then add_unique(intersect.intersection) end end if #points ~= 2 then -- print(("two triangles intersected at %f points"):format(#points)) -- print(fmt_matrix(T1)) -- print(fmt_matrix(T2)) return nil --assert(false, ("two triangles intersected at %f points"):format(#points)) end return points end --- determines the intersection coefficients and intersection point of a line segment and triangle, if it exists, or returns nil --- @param L table<table<number>> line segment defined by endpoints --- @param T table<table<number>> triangle defined by vertices --- @return table<table<table<number>>,table<table<number>>>|nil the solution coefficients and literal R3 intersection point local function line_segment_triangle_intersection(L, T) local eps = 0.0000001 local num = 0 for _, P1 in ipairs(L) do for _, P2 in ipairs(T) do if distance({P1}, {P2}) < eps then num = num + 1 end end end if num > 1 then return nil end local LO = {L[1]} local LU = vector_subtraction({L[2]}, LO) local LA = {LO[1], LU[1]} local TO = {T[1]} local TU = vector_subtraction({T[2]}, TO) local TUA = {TO[1], TU[1]} local TV = vector_subtraction({T[3]}, TO) local TVA = {TO[1], TV[1]} local TA = {TO[1], TU[1], TV[1]} local TUVA = { vector_addition(TO, TU)[1] ,vector_subtraction(TV, TU)[1] } local coeffs = line_plane_intersection(LA, TA) if coeffs == nil then return nil end if #coeffs.freevars == 0 then local t = coeffs.solution[1] if 0-eps<=t and t<=1+eps then local I = vector_addition( LO, scalar_multiplication(t, LU) ) if point_in_triangle(I, T) then return { solution = coeffs, intersection = I } end end end return nil end --- obtains the coordinates and free variables of the intersection --- between a line and a plane, each defined by their affine bases. --- @param L table<table<number>> an affine basis of a line --- @param T table<table<number>> an affine basis of a plane --- @return table<table<number>> the solution and free variables local function line_plane_intersection(L, T) local LO = {L[1]} local LU = {L[2]} local TO = {T[1]} local TU = {T[2]} local TV = {T[3]} --- LO + (t) * LU = TO + (s) * TU + (w) * TV -- (t) * LU - (s) * TU - (w) * TV = TO - LO local rhs = vector_subtraction(TO, LO) local augmented_matrix = { {LU[1][1], LU[1][2], LU[1][3]}, {-TU[1][1], -TU[1][2], -TU[1][3]}, {-TV[1][1], -TV[1][2], -TV[1][3]}, {rhs[1][1], rhs[1][2], rhs[1][3]} } local sol = gauss_jordan(augmented_matrix) if not sol then -- print("No solution: line-plane system inconsistent") return nil end if #sol.freevars > 0 then -- print("Line lies in the plane (coplanar case). Free vars:", #sol.freevars) end return sol end --- determines the solution coefficients and solution set of two line segments, or produces nil --- @param L1 table<table<number>> the first line segment --- @param L2 table<table<number>> the second line segment --- @return table<table<table<number>>,table<table<number>>>|nil the solution coefficients and solution set local function line_segment_line_segment_intersection(L1, L2) local num = 0 for _, P1 in ipairs(L1) do for _, P2 in ipairs(L2) do if distance({P1}, {P2}) < eps then num = num + 1 end end end if num ~= 0 then return nil end local L1O = {L1[1]} local L1U = vector_subtraction({L1[2]}, L1O) local L1A = {L1O[1], L1U[1]} local L2O = {L2[1]} local L2U = vector_subtraction({L2[2]}, L2O) local L2A = {L2O[1], L2U[1]} local coeffs = line_line_intersection(L1A, L2A) if coeffs == nil then return nil end if #coeffs.solution == 0 then return nil end local t, s = coeffs.solution[1], coeffs.solution[2] if 0 < t - eps and t < 1 - eps and 0 < s - eps and s < 1 - eps then return { coefficients = coeffs, intersection = vector_addition( L1O, scalar_multiplication(t, L1U) ) } end return nil end --- return coordinates and free variables for line-line intersection --- @param L1 table<table<number>> affine basis of a line --- @param L1 table<table<number>> another 1D affine basis --- @return table<table<number>> the solution and free variables local function line_line_intersection(L1, L2) local L1O = {L1[1]} local L1U = {L1[2]} local L2O = {L2[1]} local L2U = {L2[2]} -- L1O + (t) * L1U = L2O + (s) * L2U -- (t) * L1U - (s) * L2U = L1O - L2O local rhs = vector_subtraction(L2O, L1O) local augmented_matrix = { {L1U[1][1], L1U[1][2], L1U[1][3]}, {-L2U[1][1], -L2U[1][2], -L2U[1][3]}, {rhs[1][1], rhs[1][2], rhs[1][3]} } return gauss_jordan(augmented_matrix) end --- CAUTION: CHATGPT GENERATED -- Correct column-major Gauss-Jordan solver (drop-in replacement) -- M is an array of columns; each column is an array of n rows. -- Last column is RHS. Returns: -- {solution = {..}, freevars = {..}} on success -- nil on inconsistency --- @param M table<table<number>> an augmented matrix --- @return table<table<number>> the solution set and free variables local function gauss_jordan(M) -- basic validation local m = #M -- number of columns (vars + RHS) if m == 0 then return {} end local n = #M[1] -- number of rows (equations) local vars = m - 1 if vars < 1 then return nil end for c = 1, m do if #M[c] ~= n then return nil end end -- Work on a local copy local cols = {} for c = 1, m do cols[c] = {} for r = 1, n do cols[c][r] = M[c][r] end end local rank = 0 local row = 1 local pivot_cols = {} -- track pivot columns -- Gauss–Jordan elimination for col = 1, vars do -- find pivot row in column col, rows row..n local pivot_row = nil local maxval = eps for r = row, n do local v = math.abs(cols[col][r]) if v > maxval then maxval = v pivot_row = r end end if pivot_row then -- swap pivot_row with current row if pivot_row ~= row then for c = 1, m do cols[c][row], cols[c][pivot_row] = cols[c][pivot_row], cols[c][row] end end -- normalize pivot row local pivot = cols[col][row] for c = 1, m do cols[c][row] = cols[c][row] / pivot end -- eliminate column in other rows for r = 1, n do if r ~= row then local factor = cols[col][r] if math.abs(factor) > eps then for c = 1, m do cols[c][r] = cols[c][r] - factor * cols[c][row] end cols[col][r] = 0 end end end pivot_cols[#pivot_cols+1] = col rank = rank + 1 row = row + 1 if row > n then break end end end -- check for inconsistency: [0 0 ... | b] with b≠0 for r = rank+1, n do local all_zero = true for c = 1, vars do if math.abs(cols[c][r]) > eps then all_zero = false break end end if all_zero and math.abs(cols[m][r]) > eps then return nil -- inconsistent end end -- Identify free variables local freevars = {} local pivotset = {} for _,c in ipairs(pivot_cols) do pivotset[c] = true end for c = 1, vars do if not pivotset[c] then freevars[#freevars+1] = c end end -- Extract one particular solution local sol = {} for i = 1, vars do sol[i] = 0 end for k,pcol in ipairs(pivot_cols) do sol[pcol] = cols[m][k] -- solution from reduced form end return {solution = sol, freevars = freevars} end
- Adding a colormap to a solution curve of a vector fieldby Black Mild on October 7, 2025 at 8:29 pm
Here the curve is drawn with a single color (red) It's easy to get the solution curve. The below figure is drawn in this app for y'=x^2+y^2-1, y(0)=1/2. As you can notice the color of the curve is varying from red (x<-1) to purple (-1<x<1) then to blue (x>1). It is not color set of the rainbow, so it is not synchronious to the Rainbow colormap. My question: How to add a given colormap (such as Rainbow) to a solution curve of a vector field? I guess this is a kind of popular, but can not find a way with Asymptote. I expect not only Asymptote code but also any others as TikZ, MetaPost, lua, etc. The code should be apply for any colormaps Please use my code here as MWE. Update: another MWE with AI and my poor Python import numpy as np import matplotlib.pyplot as plt from matplotlib.collections import LineCollection from matplotlib.colors import Normalize from scipy.integrate import solve_ivp # ============================================================ # 1. Configuration # ============================================================ x_min, x_max = -3, 3 y_min, y_max = -3, 3 density = 8 # Number of initial conditions per axis def ode_func(t, y): """ ODE: y' = x^2 + y^2 - 1 Here, t plays the role of x. """ return t**2 + y[0]**2 - 1 def exit_box(t, y): """ Event function: stop integration when the solution leaves the box |x| <= 3, |y| <= 3. """ return max(abs(t), abs(y[0])) - 3 exit_box.terminal = True # ============================================================ # 2. Figure setup # ============================================================ fig, ax = plt.subplots(figsize=(8, 8)) # Initial conditions x_inits = np.linspace(x_min, x_max, density) y_inits = np.linspace(y_min, y_max, density) manual_starts = [ (-2.7, 0), (-2.7, 1), (-2.7, 2), ( 2.7, 0), ( 2.7,-1), ( 2.7,-2), (-0.75, 2), (0.75, -2), (-1, 0), (1, 0) ] starts = [(x0, y0) for x0 in x_inits for y0 in y_inits] starts += manual_starts all_segments = [] all_values = [] print("Computing solution curves...") # ============================================================ # 3. Solve ODEs and collect line segments # ============================================================ for x0, y0 in starts: for direction in [1, -1]: t_span = [x0, direction * 3.2] sol = solve_ivp( ode_func, t_span, [y0], events=exit_box, max_step=0.05 ) x = sol.t y = sol.y[0] if len(x) > 1: points = np.array([x, y]).T.reshape(-1, 1, 2) segments = np.concatenate([points[:-1], points[1:]], axis=1) all_segments.extend(segments) slopes = x[:-1]**2 + y[:-1]**2 - 1 all_values.extend(slopes) all_values = np.array(all_values) # ============================================================ # 4. Background vector field (normalized) # ============================================================ X, Y = np.meshgrid( np.linspace(x_min, x_max, 20), np.linspace(y_min, y_max, 20) ) U = np.ones_like(X) V = X**2 + Y**2 - 1 N = np.sqrt(U**2 + V**2) ax.quiver( X, Y, U / N, V / N, color="gray", alpha=0.3, pivot="mid" ) # ============================================================ # 5. LineCollection with true rainbow colormap # ============================================================ norm = Normalize( vmin=np.percentile(all_values, 5), vmax=np.percentile(all_values, 95) ) lc = LineCollection( all_segments, cmap="rainbow", norm=norm, linewidth=1.5, alpha=0.85 ) lc.set_array(all_values) ax.add_collection(lc) # ============================================================ # 6. Axes styling and annotations # ============================================================ ax.set_xlim(x_min, x_max) ax.set_ylim(y_min, y_max) ax.set_aspect("equal", adjustable="box") ax.set_xlabel("x") ax.set_ylabel("y") ax.set_title(r"Solution curves for $y' = x^2 + y^2 - 1$") cbar = plt.colorbar(lc, ax=ax) cbar.set_label(r"Slope value $y' = x^2 + y^2 - 1$") ax.grid(True, linestyle=":", alpha=0.6) plt.tight_layout() plt.savefig("solution_curves_rainbow.png", dpi=200) plt.show()
- Draw vector field on top of surface of spherical octant, but not in specific regionsby Johannes Nauta on February 9, 2024 at 1:40 pm
I am interested in drawing a vector-like field towards, or away from, a single point on the surface of a unit octant. If possible, I would like to constrain this to not occur within an area spanned by some paths. I have the following code in place that produces the image shown below. I furthermore highlighted what I would like. \documentclass[border=10pt]{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} \usetikzlibrary{arrows.meta} \begin{document} \tdplotsetmaincoords{65}{120} \begin{tikzpicture}[ scale=2.5, tdplot_main_coords, Arrow/.style={-{Latex[scale=.7]}}, ] % Draw axes \draw[->] (0,0,0) -- (1.2,0,0) node[inner sep=0pt, below left] (r2) {$r_2$}; \draw[->] (0,0,0) -- (0,1.2,0) node[inner sep=0pt, below right] (r1) {$r_1$}; \draw[->] (0,0,0) -- (0,0,1.2) node[inner sep=0pt, above] (r3) {$r_3$}; % quarter circle on xy plane \draw[dashed] (1,0,0) arc (0:90:1); % -- (0,0,0) -- cycle; % quarter circle on xz plane \tdplotsetthetaplanecoords{0} \draw[dashed, tdplot_rotated_coords] (1,0,0) arc (0:90:1); % -- (0,0,0) -- cycle; % quarter circle on yz plane \tdplotsetthetaplanecoords{90} \draw[dashed, tdplot_rotated_coords] (1,0,0) arc (0:90:1); % -- (0,0,0) -- cycle; \node (A1) at (0.7,0.7,0.1) {}; \node (A2) at (0.7,0.1,0.7) {}; \node (A3) at (0.1,0.7,0.7) {}; % Draw triangle on surface with corners A1...A3 \draw[blue] (A1.center) edge[bend left] (A2.center); \draw[blue] (A2.center) edge[bend left] (A3.center); \draw[blue] (A3.center) edge[bend left] (A1.center); \end{tikzpicture} \end{document} This is what I currently have. This is what I'd like. If possible, I would like to keep it as simple as possible, but I understand that 3D coordinates bring with them some more complicated calculations. If there is also an external library that makes this far easier, I'd be more than happy to learn about it as well.
- Schematic representation of emittersby Антон on December 7, 2023 at 5:00 am
I started drawing emitters, but I ran into difficulties. \documentclass[10pt,border=3mm,tikz]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % arc \draw (-0.15,0.3) % Coordinates of the arc center (x, y) arc (30:150:1); % Starting angle: 30 degrees, Ending angle: 150 degrees, Radius: 1 % Vertical line \draw (-1,2) % Initial coordinates (x, y) -- % Operator for drawing a line (-1,0.1); % Final coordinates (x, y) % Horizontal line \draw (-1.4,0.1) % Initial coordinates (x, y) -- % Оператор для рисования линии (-0.6,0.1); % Final coordinates (x, y) % Axes \draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$}; \draw[->] (0,-1.5) -- (0,1.5) node[above] {$y$}; \end{tikzpicture} \end{document} it is required to draw a complete picture, but so far I have just started the emitter and do not know how to set the coordinates correctly and how to make it more similar. A few hours later, I received such a drawing. Of course, it looks too little like the original: \documentclass[10pt,border=3mm,tikz]{standalone} \begin{document} \tikzset{ mylabel/.style={font=\scriptsize} } \begin{tikzpicture}[ antenna/.pic={ % Antenna drawing \draw (-0.57,.15) arc(50:130:0.7); \draw (-1,1) -- (-1,.1); \draw (-1.2,.1) -- (-0.8,.1); }, Pattern/.pic={ % Radiation pattern drawing \draw[thick] (0,0) ellipse (0.1 and 0.5); \draw[dashed] (0,\R) -- (0,0); } ] % Positions of emitters and axis labels \def\positionOne{-1} \def\positionZero{0} \def\positionTwo{1} \def\R{2} % R \def\alpha{18} % Angle % Placement of emitters and radiation pattern \pic at (\positionOne+1,0.3) {antenna}; \node[below, mylabel] at (\positionOne+0.5,1.2) {№ 1}; \pic at (\positionTwo+1,0.3) {antenna}; \node[below, mylabel] at (\positionTwo+0.5,1.2) {№ 2}; \pic[rotate=-\alpha,scale=1, red!100] at (\positionZero,-\R) {Pattern}; \draw[dashed] (\positionZero,-\R) -- (\positionZero,0); \node[below, mylabel] at (\positionZero-0.25,-\R/3) {R}; \draw[dashed] (\positionZero,-\R) -- (\positionTwo,0); % Axes \draw[->] (\positionOne-0.5,0) -- (\positionTwo+0.5,0) node[right] {$X$}; % Labels on the axis \node[below, mylabel] at (\positionOne,0) {$\positionOne$}; \node[below, mylabel] at (\positionZero,0) {$\positionZero$}; \node[below, mylabel] at (\positionTwo,0) {$\positionTwo$}; % Ticks on the axis \foreach \x in {\positionOne,\positionZero,\positionTwo} \draw (\x,0.1) -- (\x,-0.1); \end{tikzpicture} \end{document}
- Rotate ellipsoid in Tikz environmentby Debora on September 2, 2022 at 8:58 am
This is the result of my code: Now, I would like to have the inner ellipsoid aligned with the x-axis, and not with the y-axis as it is. In other words, I would like to rotate the all ellipsoid in the xy-plane by 90 degrees, so I should introduce some prospective somehow, like this (in black where I want to place the ellipsoid): How should I modify my code? (Simplified code without axis and lines, but that's not important) \begin{tikzpicture}[scale = 0.3][line cap=round, line join=round] \draw [ball color=white,very thin,opacity=0.4] (0,0,0) circle (8) ; \fill[white,opacity=0.6] (0,0) circle (8 and 3); \shade[right color=orange,middle color=red,left color=blue,opacity=0.4,shading angle=-110] (0,0) circle (8 and 3); \shade[ball color=orange,opacity=0.3] (0,0) circle (8 and 3); \draw[line width=0.5pt,rotate around={0.:(0.,0.)},dash pattern=on 4pt off 3pt, color = violet, opacity = 0.6] (0,0) ellipse (1 and 3); \end{tikzpicture}
- control systems block diagram on latexby ananimeaddict_ on December 14, 2021 at 11:37 pm
I'm using an example I found online: https://texample.net/tikz/examples/control-system-principles/, to draw this diagram: so far I have: \documentclass{article} \usepackage{lmodern} \usepackage{graphicx} \usepackage{lscape} \usepackage{tocbibind} \usepackage{listings} \usepackage{tikz} \usepackage{amsmath} \usetikzlibrary{shapes, arrows.meta, arrows, positioning} \begin{document} \tikzstyle{block} = [draw, rectangle, minimum height=3em, minimum width=6em] \tikzstyle{sum} = [draw, circle, node distance=1.5cm] \tikzstyle{input} = [coordinate] \tikzstyle{output} = [coordinate] \tikzstyle{pinstyle} = [pin edge={to-,thin,black}] \begin{tikzpicture}[auto, node distance=3cm,>=latex'] \node [input, name=input] {}; \node [block, right of=input] (controller) {{$\dot x = Ax(t) + Bu(t)$}}; \draw [draw,->] (input) -- node {$u$} (controller); \node [block, right of=controller, node distance=4cm] (system) {C}; \node [output, right of=system] (output) {}; \draw [->] (system) -- node [name=y] {$y$}(output); \node [block, below of=controller] (new controller) {{$\dot{\hat{x}} = \hat{A}\hat{x}(t) + \hat{B}u(t)$}}; \node [block, right of=new controller, node distance=4cm] (new system) {$\hat{C}$}; \node [output, right of=new system] (new output) {}; \node[sum, right of =new output] (sum) {}; \draw [->] (new system) -- node [name=y] {$\hat{y}$}(new output); \node [block, below of=new system] (observer) {{$L$}}; \draw [->] (controller) -- node[name=u] {$x$} (system); \draw [->] (new controller) -- node[name=u] {$\hat{x}$} (new system); \end{tikzpicture} \end{document} and I'm stuck with getting the circle/sum node at the end or edge of y hat. It is too far out. any help with drawing this diagram would be appreciated, as I've been stuck with the sum node position for a while. many thanks! edit 1: edited and included packages and such as it wasn't included before, apologies! (I've included other packages as this is a part of a greater file and is just a section). Would also appreciate if possible if L had an arrow going into xhat(t)=... as shown in the diagram please! edit 2: thank you to Rushi and Zarko for their help. it helped me improve mine, and I used things I learnt from both codes to produce: the code being: \documentclass{article} \usepackage{tikz} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usetikzlibrary{shapes, arrows.meta,arrows, positioning,chains, quotes} \begin{document} \tikzstyle{block} = [draw, rectangle, minimum height=3em, minimum width=6em] \tikzstyle{sum} = [draw, circle, node distance=1.5cm] \tikzstyle{input} = [coordinate] \tikzstyle{output} = [coordinate] \tikzstyle{pinstyle} = [pin edge={to-,thin,black}] \begin{tikzpicture}[auto,>=latex'] \node [input, name=input] {}; \node [block, right=1cm of input] (system) {{$\dot x = Ax(t) + Bu(t)$}}; \node [block, right=1cm of system] (C) {C}; \node [output, right=2cm of C] (output) {}; \node [block, below=1cm of system] (observer) {{$\dot{\hat{x}} = \hat{A}\hat{x}(t) + \hat{B}u(t)$}}; \node [block, right=1cm of observer] (CHat) {$\hat{C}$}; \node [output, right=1cm of CHat] (new output) {}; \node [sum] at (output |- CHat) (sum) {}; \node [block, below=1cm of CHat] (L) {{$L$}}; \draw [-] (input) -- ++(-1,0); \draw [->] (input) -- node {$u$} (system); \draw [-] (C) -- node [name=y] {$y$} (output); \draw [->] (output) -- ++(1,0); \draw [->] (CHat) -- node [name=y] {$\hat{y}$} node [below,at end] {$-$} (sum); \draw [->] (system) -- node [name=x] {$x$} (C); \draw [->] (observer) -- node [name=xHat] {$\hat{x}$} (CHat); \draw [->] (output) -- (sum); \draw [->] (sum) |- node[name=u] [right, near start] {$e$} (L); \draw [->] (input) |- (observer); %\draw [->] (L) -| (observer); \draw [->] (L) -- (input |- L) |- ([yshift=-1ex] observer.west); \draw [->] (xHat) -- ++(0,-4); \end{tikzpicture} \end{document}
- Is it possible to highlight every cell with counters `iRow `and `jCol` in `NiceTabular`?by Al-Motasem Aldaoudeyeh on November 14, 2021 at 7:07 pm
It is very common for me to need to place braces in matrix environment in a controlled fashion which I find NiceTabular environment suitable for such purpose. One difficulty I encounter is that when tables are very large in size, it becomes harder to determine the position of each cell in the table. Is it possible to systematically highlight the cells numbers using the counters iRow and jCol as follows? The following requirements are to be met The highlighting color and transparency should be controllable Highlighting should go exactly in the middle of each cell (even when \Block environment is used, cells of the \Block should still be highlighted) If possible, the highlighting should be done using a convenient key to be added in the options My MWE \documentclass[11pt, a4paper]{article} \usepackage{nicematrix} \usepackage{calc} \newlength{\widthCell} \newcommand{\phantombox}[2]{% \setlength{\widthCell}{\widthof{{Cell \arabic{iRow},\arabic{jCol}}}}% {#2}\llap{\parbox{\widthCell}{\centering\color{gray!25}#1}}% } \begin{document} \begin{NiceTabular}[hvlines,rules/color=[gray]{0.89},rules/width=0.2pt]{*{3}c} \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} \\ \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} \\ \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} \\ \CodeAfter \SubMatrix{\{}{1-1}{3-1}{.} \SubMatrix{.}{1-2}{2-2}{\}} \end{NiceTabular} \end{document}
- Limit scope of node properties to current node only in tikzby fuenfundachtzig on October 16, 2021 at 7:34 pm
I'm defining a command to draw a red box with nice rounded corners around text or graphics elements in LaTeX with tikz: \documentclass{article} \usepackage{tikz} \begin{document} % command to draw a box around something \newcommand{\boxed}[1]{ \tikz \node (boxedword) [draw, rectangle, red, thick, rounded corners=10mm] {#1};% } Normal rectangle: \begin{tikzpicture} \node [rectangle, draw, minimum size=4.0cm] {}; \end{tikzpicture} Boxed rectangle: \boxed{ % same rectangle as above \begin{tikzpicture} \node [rectangle, draw, minimum size=4.0cm] {}; \end{tikzpicture} } \end{document} Unfortunately, the properties I set for the node (rounded corners and color) are propagated to all subnodes, which is not what I want: of course, the text or graphics within the box should be unchanged. How do I fix that? Desired output: black rectangle with sharp corners inside red rectangle with rounded corners.
- How to set global options / parameters in Circuitikz?by Richard Robinson on July 25, 2018 at 6:10 pm
I use Circuitikz quite often with modified sizing as styles as follows: \begin{circuitikz}[line width=0.7pt, line join=round] \draw (0,0) ... to [/tikz/circuitikz/bipoles/length=22pt, L] (1,0) \end{circuitikz} Is there a way to set global parameters such that I don't have to add the custom line width, join, and capacitor/inductor size each instance? I have tried adding them after "american" in \usepackage[american,...]{circuitikz} but it does not work. Thank you very much.
- Circular Motionby oo2t on October 2, 2016 at 2:27 pm
I'm trying to draw three vectors that are tangent to the circle, as shown below. Is it possible to use \foreach to duplicate one vector around the circle? If so, can someone help me to draw this picture?