TikZ
- Problems with figures when submitting to arXivby InsideOut on November 27, 2025 at 10:46 am
I am trying to upload a paper to arXiv that contains several figures, some in jpg format and many others generated with TikZ. The jpg figures compile fine, but the TikZ-generated figures appear completely black in the output PDF, especially those where I use commands like opacity or patterns. I have tried setting \pdfoutput=1, but the issue persists. The paper compiles correctly on Overleaf, but arXiv fails to render the TikZ figures properly. I am looking for a way to make TikZ figures appear correctly on arXiv without converting them to external PDFs. It seems that something on arXiv has changed recently, because I was able to solve the same problem the last March using \pdfoutput=1, but as mentioned, this no longer works. What can be done?
- `scale` of pic's inconsistency behaviour of text and node and linewidth in `tikz`? [duplicate]by Explorer on November 27, 2025 at 10:38 am
The case looks similar to: tikz .pic scaling with text How to scale a tikzpicture including texts? But I think not exactly the same, at least for line width: The following is my code: \documentclass[tikz,border=10pt]{standalone} \begin{document} \begin{tikzpicture}[ explorer/.pic={% \node[% draw,fill=yellow!50, line width=2pt, rounded corners, text=red,font=\scshape\Huge, minimum width=10 cm, minimum height=3 cm, inner sep=0pt, outer sep=0pt, ] (tmp) {ABCDE}; \draw[magenta,line cap=round,line width=1.5pt] ([shift={(1cm,-.5cm)}]tmp.north west) -- ([shift={(-1cm,-.5cm)}]tmp.north east); \draw[magenta,line cap=round,line width=1.5pt] ([shift={(1cm,.5cm)}]tmp.south west) -- ([shift={(-1cm,.5cm)}]tmp.south east); \draw[red,ultra thick,rounded corners=2pt,line width=5pt] ([shift={(3pt,-3pt)}]tmp.north west) rectangle ([shift={(-3pt,3pt)}]tmp.south east) ; } ] \draw[gray] (-10,-15) grid (10,5); \pic at (0,0) {explorer}; \pic[scale=.5] at (-5,-5) {explorer}; \pic[scale=.5,transform shape] at (5,-5) {explorer}; \pic[scale=.25] at (-5,-10) {explorer}; \pic[scale=.25,transform shape] at (5,-10) {explorer}; \node[scale=.25] at (0,3) {\tikz \pic{explorer};}; \end{tikzpicture} \end{document} I want to scale THE WHOLE pic as a whole content to scale. I could achieve what I want via nested tikzpicture inside \node, but that is NOT recommaneded. However, with the remaining case, scale even with transform shape all didn't work as expected.
- TikZ forest: how to add diagonal dots to a directory tree?by Grass on November 27, 2025 at 6:03 am
How do I draw a node of diagonal dots like this, for this base directory tree style by cfr? Ideally, I want this to work with ‘vertical dots’ --- the forest keys extensible edge and extend presented here by cfr. I tried looking at edge path to see if I what I could figure out, but not much luck thus far. As per Jasper’s request, here is an MWE (ripped from cfr’s post): \documentclass[border=10pt,multi,tikz]{standalone} \usepackage[edges]{forest} \definecolor{folderbg}{RGB}{124,166,198} \definecolor{folderborder}{RGB}{110,144,169} \newlength\Size \setlength\Size{4pt} \tikzset{% folder/.pic={% \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ; }, } \forestset{% declare autowrapped toks={pic me}{}, declare boolean register={pic root}, pic root=0, pic dir tree/.style={% for tree={% folder, font=\ttfamily, grow'=0, }, before typesetting nodes={% for tree={% edge label+/.option={pic me}, }, if pic root={ tikz+={ \pic at ([xshift=\Size].west) {folder}; }, align={l} }{}, }, }, pic me set/.code n args=2{% \forestset{% #1/.style={% inner xsep=2\Size, pic me={pic {#2}}, } } }, pic me set={directory}{folder}, pic me set={file}{file}, } \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] [templates ] [tests ] ] \end{forest} \end{document}
- TikZ word search diagramby yannis on November 26, 2025 at 11:50 pm
How can I draw such a "word-search" diagram in TikZ? I need to place the letters on a grid and then to add red horizontal, vertical, diagonal or antidiagonal highlighting boxes as in the picture.
- How to customize CircuiTikz ac - dc symbolsby Anisio Braga on November 26, 2025 at 8:12 pm
The ac & dc symbols in Circuitikz are a much welcomed addition. However, I could not find a proper way customize it to a typical application in a multimeter dial with the ac or dc symbol positioned above the letter, besides changing the thickness of the lines. How can this be done with the new ac and dc symbols used in the didactic multimeter in the following code. \documentclass[10pt]{article} \usepackage[usenames]{color} %used for font color \usepackage[utf8]{inputenc} %useful to type directly diacritic characters \usepackage[siunitx,american, RPvoltages]{circuitikz} \usetikzlibrary{positioning,fit} \usepackage{physics} \usepackage{ifthen} \usepackage{xcolor} \usepackage{xargs} % for using extra optional arguments % Defining Matlab default colors with portuguese names to avoid conflicts \definecolor{lara}{rgb}{0.8500 0.3250 0.0980} \definecolor{azul}{rgb}{0.0000 0.4470 0.7410} \definecolor{verm}{rgb}{1.0000 0.3100 0.3900} \definecolor{amar}{rgb}{0.9290 0.6940 0.1250} \definecolor{roxo}{rgb}{0.4940 0.1840 0.5560} \definecolor{verd}{rgb}{0.4660 0.6740 0.1880} \definecolor{azcl}{rgb}{0.3010 0.7450 0.9330} \definecolor{marr}{rgb}{0.6350 0.0780 0.1840} \definecolor{ouro}{rgb}{0.9961 0.6667 0.2275} %-------------------- % Definitions to help locate nodes. Comment out the second definition when done! \def\coord(#1){coordinate(#1)} %\def\coord(#1){node[circle, inner sep=1pt,pin={[teal, overlay, inner sep=0.5pt, font=\tiny, pin distance=0.3cm, pin edge={teal, line width=0.5pt, shorten <=-2pt, {Kite[length=1.5mm]}-{Circle[open,line width=0.5pt,length=0.75mm]}}]45:#1}](#1){}coordinate(#1)} \newcommandx{\probe}[7][1=red, 3=45:0.5, 5=$+$, 6=0.25pt, 7=5pt] %[color]{x,y}[angle:radius]{name}[label][line width][-Kite length] {\draw[#1, line width = #6,-{Kite[length=#7]}] ($(#2)+(#3)$) node[circle, very thin, inner sep=0pt, minimum size=5pt, draw=#1, fill=#1!10,font=\tiny](#4){#5} to (#2); } % DC and AC symbols \newcommand{\mathdirectcurrent}{\mathrel{\mathpalette\mathdirectcurrentinner\relax}} \newcommand{\mathdirectcurrentinner}[1]{% \settowidth{\dimen0}{$#1=$}% \vbox to .75ex {\offinterlineskip \hbox to \dimen0{\leaders\hrule height 0.65pt \hfill} \vskip.25ex \hbox to \dimen0{% \leaders\hrule height 0.35pt \hskip.25\dimen0\hfill \leaders\hrule height 0.35pt \hskip.25\dimen0\hfill \leaders\hrule height 0.35pt \hskip.25\dimen0 } \vfill }% } \newcommand{\textdirectcurrent}{\mathdirectcurrentinner{\textstyle}{}} %----------------------------------------- \newcommand{\DCACsup}[1]{$\widetilde{\stackrel{\mathdirectcurrentinner{}}{\rm #1}}$} \newcommand{\DCsup}[1]{$\stackrel{\mathdirectcurrentinner{}}{\rm #1}$} \begin{document} %->/Multimeters \scalebox{1}{% % ---- Multimeter ------------- \tikzset{pics/Multimeter/.style={code={ \tikzset{Multimeter/.cd,#1} \def\pv##1{\pgfkeysvalueof{/tikz/Multimeter/##1}}% local object variable %------------------------------ \def\mmw{1*2} % width \def\mmh{1.6*2} % height %---------- \path (0,0) \coord(-MM0); \draw[\pv{body border}, thin, fill=\pv{body border}, rounded corners=1mm] (0,0) rectangle (\mmw,\mmh); \draw[\pv{body border}, thin, fill=\pv{body},opacity=0.75, rounded corners=1mm] ($(-MM0)+(0.05*\mmw,0.05*\mmw)$) rectangle (0.95*\mmw,\mmh-0.05*\mmw); % --- nodes for tag positioning %--- display \draw[gray,fill=gray!10,rounded corners=0.5mm] ($(-MM0)+(0.1*\mmw,0.7*\mmh)$)\coord(MMdisplay0) rectangle (0.9*\mmw,0.925*\mmh) \coord(MMdisplay1); %--- Displayed value \node[left, align=right,rotate=0] at ($(MMdisplay1)+(0.05*\mmw,-0.11*\mmh)$) {\large \pv{value}}; %--- center dial \draw[gray!80!\pv{body},thick,very thin, fill=white] ($(-MM0)+(0.5*\mmw,0.45*\mmh)$)\coord(-MM0center) circle[radius=0.25*\mmw]; \node at (-MM0center) {}; \foreach \x/\y in {-45/mA,0/$\widetilde{\mathrm{A}}$,45/$\stackrel{\mathdirectcurrentinner{}{}}{\mathrm{A}}$,90/$\Omega$,135/ $\stackrel{\mathdirectcurrentinner{}{}}{\mathrm{V}}$,180/ $\widetilde{\mathrm{V}}$,-135/{\textsf{OFF} \qquad}} { \draw (-MM0center) ++ (\x:0.325*\mmw) node[blue] {\tiny \y};} \foreach \x in {-45,0,45,90,135,180,-135} \draw (-MM0center) ++ (\x:0.25*\mmw) -- ++(\x:0.025); % \draw[line width = 1.5mm, black!50,->,-{Kite[length=3mm,width=2mm]}] (-MM0center) -- ++ (225-\pv{dial}*45:0.24*\mmw); \draw[line width = 1.5mm, black!50,->,-{Triangle Cap[length=1.75mm]}] (-MM0center) -- ++ (225-\pv{dial}*45:0.24*\mmw); \draw[line width = 1.5mm, black!50, -Round Cap] (-MM0center) -- ++ (225-\pv{dial}*45:-0.24*\mmw); \draw[gray!70!black,thick, fill=gray] (-MM0center) circle[radius=1mm]; %--- tag \node at ($(-MM0center)+(\pv{tag pos})$){\pv{tag}}; %--- bornes % \draw[black,very thin, fill=gray] ($(-MM0)+(0.5*\mmw,0.25*\mmw)$)\coord(-COM) circle[radius=0.1]; \node [bnc,thick, color=black, anchor=zero, rotate=\pv{COMout}, scale=1](COMbnc) at ($(-MM0)+(0.5*\mmw,0.2*\mmw)$){}; \path (COMbnc.center) \coord(-COM); \ifthenelse{\equal{\pv{ampere}}{on}}{ % amperimeter probe on % \draw[red!30!black,very thin, fill=red] ($(-MM0)+(0.2*\mmw,0.25*\mmw)$) \coord(-Aprobe) circle[radius=0.1]; \node [bnc, color=red,thick, anchor=zero, rotate=\pv{Aout}, scale=1](Abnc) at ($(-MM0)+(0.2*\mmw,0.2*\mmw)$){}; \path (Abnc.center) \coord(-A); % \draw[thick,-{Triangle[width=1.5mm,length=1.75mm, sep=1*\mmw mm]Circle[length=0.1mm]},gray] (Abnc.zero) -- (COMbnc.zero); \draw[thick,-{Triangle[width=1.5mm,length=1.75mm]},gray!50!black, opacity = \pv{current} ] (Abnc.zero) -- ($ (Abnc.zero) !0.65!(COMbnc.zero)$); \draw[thick,gray!50!black, opacity = \pv{current} ] ($ (Abnc.zero) !0.6!(COMbnc.zero)$) -- (COMbnc.zero); \node[above=0.1, align=center,font=\tiny] at (Abnc.zero){\textbf{A}}; }{} \ifthenelse{\equal{\pv{volt}}{on}}{%voltmeter or ohmeter % \draw[red!30!black,very thin, fill=red] ($(-MM0)+(0.8*\mmw,0.25*\mmw)$)\coord(-Vprobe) circle[radius=0.1]; \node [bnc, color=red,thick, anchor=zero, rotate=\pv{Vout}, scale=1](Vbnc) at ($(-MM0)+(0.8*\mmw,0.2*\mmw)$){}; \path (Vbnc.center) \coord(-V); }{} \ifthenelse{\equal{\pv{ohm}}{on}}{%ohmmeter \node [bnc, color=red,thick, anchor=zero, rotate=\pv{Vout}, scale=1](Vbnc) at ($(-MM0)+(0.8*\mmw,0.2*\mmw)$){}; \path (Vbnc.center) \coord(-V); \draw[thick,-{Bar[width=1mm]},gray!50!black, opacity = \pv{battery}] (COMbnc.zero) -- ($ (COMbnc.zero) !0.5!(Vbnc.zero)$); \draw[thick,{Bar[width=3mm]}-,gray!50!black, opacity = \pv{battery}]($ (COMbnc.zero) !0.6!(Vbnc.zero)$) -- (Vbnc.zero); }{} \node[above=0.1, align=center,font=\tiny] at (Vbnc.zero){\textbf{V$\Omega$}}; \node[above=0.1, align=center,font=\tiny] at (COMbnc.zero){\textsf{\textbf{COM}}}; %--------------------- } % end of code }, % end of style Multimeter/.cd, tag/.initial= $V_{AB}$, tag pos/.initial= 90:2, % distancing vector from center value/.initial= $1.0^{\mathrm{mA}}$, body/.initial=yellow, body border/.initial=orange, Vout/.initial= -90, % volt bnc angle Aout/.initial = -90, % ampere bnc angle COMout/.initial= -90, % COM bnc angle text width/.initial = 1.5cm, dial/.initial = 6,% 0=OFF, 1=V~, ..., 6=mA ampere/.initial= on, % To connect an ammeter set the volt=off volt/.initial= on, ohm/.initial= off, current/.initial= 1, % current arrow opacity: 0 < current < 1 battery/.initial= 0, % ohmmeter battery opacity: 0 < battery < 1 } % End of multimeter %=======================================% \begin{circuitikz}[scale=1, transform shape,transform canvas={scale=1} ] \ctikzset{resistors/scale=0.7} \ctikzset{open voltage position=legacy} \def\dx{3} \def\dy{3} % --- circuit \draw (0,0)\coord(gnd) to[battery,v_=\SI{1}{\volt},*-] ++(0,1.25*\dy)\coord(A) to[short, f<=\color{azul}$I_1$, color=azul] ++(1.5*\dx,0)\coord(B) to[R,l=\SI{1}{\kilo\ohm},-] ++(0,-1.25*\dy) \coord(C) to[open,*-*] (gnd)node[ground]{}; % ---- Positioning probes ---- \probe[gray!50!black]{C}[180:0.75]{An}[$-$][2pt][10pt] \node [above right, font=\footnotesize] at (An){$0$V}; \probe[verm]{gnd}[0:0.75]{Ap}[$+$][2pt][10pt] % ---- voltmeter ---- \pic[scale=1,transform shape, rotate=0] (M1) at ($(gnd)+(-3.5,0)$) {Multimeter={tag=$V_{AC}$,dial=2,ampere=off, value= $1.00^{\mathrm{V}}$, Vout=0,body=red!10,body border=red!50!black}}; \probe[verm]{A}[180:0.75]{Av}[$+$][2pt][10pt] \probe[gray!50!black]{gnd}[180:0.75]{Cv}[$-$][2pt][10pt] \draw[line width = 1.5pt, red] (M1-V) to[out=0, in=180] (Av); \draw[line width = 1.5pt, black] (M1-COM) to[out=-90, in=180] (Cv); \pic[scale=1,transform shape, rotate=0] (M1) at ($(gnd)+(1.5,0)$) {Multimeter={value=$-1.0^{\mathrm{mA}}$, tag=$I_{1}$, dial=6, ampere=on, ohm=on,Aout=-90, Vout=-90,COMout=-90}}; \draw[line width = 1.5pt, red] (M1-A) to[out=-90, in=0] (Ap); \draw[line width = 1.5pt, black] (M1-COM) to[out=-90, in=180] (An); %\node at (0,-3)[dc symbol,dc symbol/height=2},dc symbol segments=3]{V}; \end{circuitikz} %---------------- }% --- End Scalebox --- \end{document}
- TikZ forest: how to add vertical dots to the 'top' or bottom of a directory tree? (continuation)by Grass on November 26, 2025 at 5:37 am
A while back, cfr kindly answered my question here. But I have some issues. 1) I want to be able to insert vertical dots at any ‘level’ of the forest tree (Ref: cfr’s first comment) I want something like this: I tried \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,extensible edge [config ] [lib, extend [file.txt, file, extend ] [file, file] ] ] \end{forest} with cfr’s MWE but it gave 2) How to adapt the code so that it works with rounded corners (Ref: cfr’s second comment) When we use for tree={edge=rounded corners}, as in the following MWE, we have extraneous white space, which the removal of |- !u.child anchor seems to solve: \documentclass[border=10pt,multi,tikz]{standalone} % ateb: https://tex.stackexchange.com/a/754955/ \usepackage[edges]{forest} \definecolor{folderbg}{RGB}{124,166,198} \definecolor{folderborder}{RGB}{110,144,169} \newlength\Size \setlength\Size{4pt} \tikzset{% folder/.pic={% \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg, sharp corners] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg, sharp corners] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10, sharp corners] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ; }, } \forestset{% declare autowrapped toks={pic me}{}, declare boolean register={pic root}, pic root=0, pic dir tree/.style={% for tree={% folder, font=\ttfamily, grow'=0, }, before typesetting nodes={% for tree={% edge label+/.option={pic me}, edge=rounded corners, }, if pic root={ tikz+={ \pic at ([xshift=\Size].west) {folder}; }, align={l} }{}, }, }, pic me set/.code n args=2{% \forestset{% #1/.style={% inner xsep=2\Size, pic me={pic {#2}}, } } }, pic me set={directory}{folder}, pic me set={file}{file}, declare toks={real siblings}{}, extensible edge/.style={% delay={% prepend={[\strut, delay={% do dynamics, temptoksa=, for following siblings={% if temptoksa={}{}{% temptoksa+={,}, }, temptoksa+/.option=name, }, real siblings/.register=temptoksa, folder, grow'=0, before computing xy={% l'=0pt, s'=-15pt, }, delay n=2{% split option={real siblings}{,}{append}, }, }, edge path'={% (!u.parent anchor) ++(\foresteregister{folder indent},0pt) -- ++(0pt,-5pt) edge [dotted] ([xshift=\foresteregister{folder indent}].parent anchor) }, ]}, }, }, extend/.style={% delay={% append={[\strut, folder, grow'=0, before computing xy={% l'=0pt, s'=-15pt, }, if n children=0{% before drawing tree={% delay={% y/.min={>O{y}}{parent,descendants}, }, }, }{}, edge path'={% (!uu.parent anchor |- !u.child anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ([yshift=15pt].parent anchor -| a) edge [dotted] (.parent anchor -| a) }, ]}, }, }, } \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system, extensible edge, [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib, extend [Access ] [Plugin ] [file.txt, file,extend ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,extensible edge [config ] [lib, extend [Access ] [Plugin ] [file.txt, file, extend ] ] ] \end{forest} \end{document} Edit I also want some lines to be of equal length, for aesthetic reasons:
- How to get a structure of this nodes tower with proper coordinates?by Explorer on November 25, 2025 at 5:54 pm
What I want to achieve is something as below(sorry for drawing in a hurry): The only requirements is vertical alignment(shown as the red dashed lines), the spacing of each nodes could be design, given that would not ruin the figure is okay. What I have tried is as below: \documentclass[tikz,border=5pt]{standalone} \newcommand\mynode[2][1]{% \node[draw,thick,minimum width=8cm,minimum height=2cm,font=\Huge\bfseries,scale=#1] at (#2) {AAAA}; } \begin{document} \begin{tikzpicture} % \mynode[1]{0,0} % \mynode[.45]{-2.25,-2} % \mynode[.45]{2.25,-2} % \mynode[.225]{-3.25,-3} % \mynode[.225]{1.25,-3} % \mynode[.225]{-1.25,-3} % \mynode[.225]{3.25,-3} %... \foreach \x[ evaluate=\x as \y using {int(2^(\x-1))} ] in {1,...,6}{ \foreach \t in {1,...,\y}{ \def\xx{\fpeval{-4 + (8/(\y+1))*\t*1.25}} \def\yy{\fpeval{(8/(\x+1))*1.25}} \mynode[\fpeval{1/\y}]{\xx,\yy} } } \end{tikzpicture} \end{document} It gives: I found that dilemma to determine the proper spacing, and exact coordinates calculation to guarentee vertical alignment at the same time. Is that any powerful tikz tools or something other (box, coffin?) to achieve this? Or I maybe just to make more effort to solve the better numerical relationship or working with the recursive structure?
- Wild Turkeys in TikZby karlh on November 25, 2025 at 4:20 pm
I have an annual scavenger hunt at Thanksgiving in which the TikZlings and TikZ ducks (and related fauna) guide my nieces and nephew through the course. Given that it is Thanksgiving, I wanted to include a turkey munching on pie and sipping wine, but the closest I can come is \documentclass{article} \usepackage{tikzlings} \begin{document} \begin{tikzpicture} \chicken[cake=orange!50!brown,wine] \end{tikzpicture} \end{document} and that just doesn't have the same ring to it. I found a good wild turkey drawn in MetaPost (Draw a turkey, a pumpkin pie, or any other object traditionally associated with Thanksgiving), but since the holiday is only two days away, I thought I'd see whether anyone was interested in making a picture of Meleagris gallopavo.
- Using TikZ with a command only defined on second passby Jason on November 25, 2025 at 3:39 pm
I have a number of commands that work a lot like the \ref command in that its true typeset value is only defined after an initial pass is performed. In the first pass they typeset ? - like the \ref command, and in the second pass that ? is instead a number or some string. It would be nice if I could use these commands inside a tikzpicture environment as a parameter. Obviously, tikz errors out when it gets the LaTeX command, and even if I can get the command to expand, it still errors due to tikz trying to understand the ? on the first pass - thus breaking the compile before it can build the correct value for a second pass. Is there a way to generically redefine a command (or tikz elements I guess?) so such commands still executes as normal on the first pass (a \ref command waits for a corresponding label to get defined so it has a value, but a generic command may execute some TeX like writing to an external file or change some settings/variables in the compile which it would still need to do on the first pass before it was defined in a way to be used in the tikzpicture env on the second pass), but it doesn't generate an error in tikz in the first pass (or the error is ignored/doesn't stop compile) so that the command gets a chance to be defined for the second pass - then have tikz actually use the command output on the second pass once it is correctly defined? Below is a MWE for what I am looking for, using a \label and \ref combo as a simple version of what I am after, but it would be ideal if it could work on generic commands that expand into arbitrary tikz code. \documentclass{article} \usepackage{tikz} \begin{document} \setcounter{section}{6} \section{Introduction}\label{temp} \ref{temp}% Should display 7 \begin{tikz}% Should display a 7 radius circle \draw circle(\ref{temp}pt); \end{tikz} \setcounter{section}{13} \section{Intro2}\label{temp2} \ref{temp2}% Should display 14 \begin{tikz}% Should display a 14 radius circle \draw circle(\ref{temp}pt); \end{tikz} \end{document} EDIT FOR MORE INFO The primary use case I want to apply this to is the \sage{arg} command, which on the first pass outputs a ? and writes out to an external file. That file is then processed before a second LaTeX pass. On the second pass, the \sage{arg} command grabs the definition of arg from the external file, and then the \sage{arg} command expands as the definition given by the external file. The actual particulars of sage itself aren't really important (I think), it's more that I want to have a normal LaTeX command get run inside a tikz environment, but without stopping the compile because its initial output is just a ?. But the first pass generates something so that on the second pass the command expands into tikZ parseable code, so that in the second pass it will then actually be used in tikzpicture correctly. In particular, I would actually expect any solution for this, to also work for \label and \ref, assuming that \ref is a number or somehow a string that tikz should be able to parse normally.
- How can I draw grid of cylinders?by minthao_2011 on November 25, 2025 at 9:02 am
I used Mathematica and tried grid of cylinder I don’t know how to draw with other tools. How can I draw it?
- Does LaTeX support abstract class like Java and C sharp?by YCH817 on November 25, 2025 at 6:16 am
I find out that Till Tantau's pgf supports OOP programming . But does it support abstract classes ? Here is a small example : \pgfooclass{mathobj}{ \attribute form LaTeX ; \attribute form Verb ; \method mathobj(#1) {% \pgfooset{form LaTeX}{\ensuremath{#1}}% } \method print LaTeX() {% \pgfoovalueof{form LaTeX}% } } \pgfoonew\mymathobj=new mathobj(x^2) \mymathobj.print LaTeX() I wish the mathobj class can be the abstract class or interface in Java , and other classes can inherit / implement it .
- Inaccurate TikZ/PGF plotby Dominique on November 24, 2025 at 6:31 pm
I'm using the following code to produce a plot: \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ width = 15cm, xtick = {0, 1, 2, 3, 4, 5}, ] \addplot[black, thick, smooth, domain=0:5] {exp(-100 * \x) + sin(\x)}; \addplot[blue, thick, smooth] table {stiff.dat}; \end{axis} \end{tikzpicture} \end{document} It produces the following plot: Here, the blue curve plots data points generated with Matlab for the same function. The blue curve is correct, but the black one is not. It seems TikZ is not able to plot the function accurately. I've read on this forum about this issue and I tried a few things: \ustikzlibrary{fpu}: did not help; that may be because the PFU is limited to 4-5 digits \usepackage{xfp}: I could not get this to work and kept getting an error with \fpeval \usepackage{expl3}: same. I must be doing something wrong. What is the correct incantation here? I would rather not resort to compiling with Lua because my document is part of series that all compile fine with PDFLaTeX. Thank you in advance!
- circuitikz: Rename self-drawn 'bipole symbol'by cis on November 24, 2025 at 4:46 pm
I drew a new bipol-symbol (which is similar to a capacitor from pgfcircbipoles.tex) and I want to be able to say \draw[] (0,0) to[newname] (2,0) to[vC] (4,0); instead of \draw[] (0,0) to[capacitor] (2,0) to[vC] (4,0); I thought I could do the same trick as here. Simply "search and replace" doesn't work. What do I have to do? %\documentclass[a4paper]{article} \documentclass[margin=5pt]{standalone} \usepackage{circuitikz} \makeatletter %% Normaly-Open-Contact Dipol Symbol ============ \ctikzset{bipoles/capacitor/height/.initial=0.35}% default 0.6 \ctikzset{bipoles/capacitor/width/.initial=0.3}% default 0.2 \pgfcircdeclarebipolescaled{capacitors} {} {\ctikzvalof{bipoles/capacitor/height}} {capacitor} {\ctikzvalof{bipoles/capacitor/height}} {\ctikzvalof{bipoles/capacitor/width}} { \pgfcirc@maybe@fill@straight@capacitor \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth} \pgfpathmoveto{\pgfpoint{2\pgf@circ@res@left}{\pgf@circ@res@up}} \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}} \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}} \pgfpathlineto{\pgfpoint{2\pgf@circ@res@left}{\pgf@circ@res@down}} \pgfpathmoveto{\pgfpoint{2\pgf@circ@res@right}{\pgf@circ@res@up}} \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}} \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}} \pgfpathlineto{\pgfpoint{2\pgf@circ@res@right}{\pgf@circ@res@down}} \pgfusepath{draw} } \pgfcirc@activate@bipole@simple{l}{capacitor} %% ============================= \makeatother \begin{document} \begin{circuitikz}[] \draw[] (0,0) to[capacitor] (2,0) to[vC] (4,0); \end{circuitikz} \end{document}
- floating point arithmetic and boolean operations with \ifthenelseby underflow on November 24, 2025 at 6:50 am
This is a follow up to my previous post about arithmetic operations and tikz I would like to performance floating point arithmetic & boolean operations in conjunction with \ifthenelse. Here is a minimal example: \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a+1.4*b < 4) \and (\a - 1.4*b)> 1 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} \end{document} Many thanks for your help!
- arithmetic operations with \ifthenelseby underflow on November 23, 2025 at 5:47 pm
Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example: \documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a + \b) < 4 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} \end{document} It is not working because \ifthenelse does not allow \a+\b. Bonus question: Is there a way to e.g. define \c = \a + \b in advance so I can use \c elsewhere, in \ifthenelse and subsequence \draw commands? EDIT: Actually what I needed is \a + 1.414*\b < 4 AND \a - 1.414*\b > 0. I thought I could handle the rest once I know how to insert arithmetic operations into \ifthenelse, but apparently it's more complicated than that. Apologies for the mixup and thanks for your help.
- how to shade an region bounded by curvesby underflow on November 22, 2025 at 6:43 pm
I have a region on the plane bounded by two hyperbolas xy = +/- C. What is the best/simplest way to shade (not filled) the "star shaped" region enclosed by these two hyperbolas? Advanced version of this question: I have two rays in the first quadrant, starting from the origin. These two rays cut out a curved wedge in the star shaped region. How I can shade this wedge in a different color from the rest of the region? Here is a MWE for the star shaped region, plus the two rays: \documentclass{amsart} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw [thick, domain=0.5:3] plot (\x, { 1.2/\x)}); \draw [thick, domain=-3:-0.5] plot (\x, { 1.2/\x)}); \draw [thick, domain=0.5:3] plot (\x, {-1.2/\x)}); \draw [thick, domain=-3:-0.5] plot (\x, {-1.2/\x)}); \draw (-3.4,0) -- (3.4,0); \draw (0,-2.6) -- (0,2.6); \draw [thick] (0,0) -- (2.2,2.2); \draw [thick] (0,0) -- (3.1,1.5); \end{tikzpicture} \end{document} Thanks for your help! EDIT: I know how to fill a polygon using \draw [filled] (coord) -- (coord) -- etc but I don't know how to handle the parabolas.
- How to recreate a DuPont schemeby Dorian on November 22, 2025 at 1:30 pm
I'd like to recreate a DuPont scheme as the image below. I’m not necessarily asking for the exact code used to recreate the graphic, but rather for the packages and commands that would allow me to do it myself. Is there anything more “accessible” than TikZ? Thank you in advance 😉
- 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
- TQFT non-usual cobordism drawingby MATIAS EZEQUIEL STICCA GONZLEZ on November 19, 2025 at 12:43 am
I'm currently trying to recreate something like this: Using of course the tikz tqft library. So, I first tried to do the "easiest" part, that is the drawing alone of every cobordism used in the relation. So, here's my attempt for that: \documentclass[10pt,border=3mm,tikz]{standalone} \usepackage{tikz} \usetikzlibrary{shapes.geometric,tqft} \usepackage{tqft} \tikzset{tqft/use nodes=true} \begin{document} \begin{tikzpicture}[ tqft, mycobordism/.style={ draw, boundary lower style={draw}, boundary upper style={draw}, circle width=0.4cm, circle depth=0.15cm, } ] \node[ tqft cap, mycobordism, cobordism height=2cm, flow=east, anchor=center ] (a) at (-0.7,0) {}; \node at (0, -0.8) {$\epsilon$}; \node at (0, -1.1) {counit}; \end{tikzpicture} \begin{tikzpicture} \tikzset{ tqft/use nodes=false, } \pic[ tqft, incoming boundary components=0, outgoing boundary components=2, genus=0, every lower boundary component/.style={draw}, every outgoing boundary component/.style={draw}, cobordism edge/.style={draw}, ]; \end{tikzpicture} \end{document} Aaaaand, as you may see, the problems begins. First, it seems that if you use a cobordism that is not the "primary ones" (I mean, pair of pants, cup, etc) then you have to add the command node=false, and then I'm unable to do two things: labelling the cobordism and rotating it so it's not looking down. Well, I can worry about the equalities later, but I'd appreciate if someone has some idea of how to "glue" cobordisms in general, so I can try it on my own and learn how to do it, because these ones are the simplest ones that I need to do. Anyways, thank you!
- TikZ forest: how to add vertical dots to the 'top' or bottom of a directory tree?by Grass on November 16, 2025 at 9:51 am
cfr provides us with a nice starting MWE to create directory trees: \documentclass[border=10pt,multi,tikz]{standalone} \usepackage[edges]{forest} \definecolor{folderbg}{RGB}{124,166,198} \definecolor{folderborder}{RGB}{110,144,169} \newlength\Size \setlength\Size{4pt} \tikzset{% folder/.pic={% \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ; }, } \forestset{% declare autowrapped toks={pic me}{}, declare boolean register={pic root}, pic root=0, pic dir tree/.style={% for tree={% folder, font=\ttfamily, grow'=0, }, before typesetting nodes={% for tree={% edge label+/.option={pic me}, }, if pic root={ tikz+={ \pic at ([xshift=\Size].west) {folder}; }, align={l} }{}, }, }, pic me set/.code n args=2{% \forestset{% #1/.style={% inner xsep=2\Size, pic me={pic {#2}}, } } }, pic me set={directory}{folder}, pic me set={file}{file}, } \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \end{document} But how do I add vdots at the top of the directory tree --- more precisely, right below [system] --- and at the bottom of the directory tree? Here are the respective illustrations of the results I wish to achieve: I tried looking at edge path, the names of the forest nodes, and forest anchors in forest's documentation, but I couldn't get anywhere close to the results I want.
- How can I draw a filled plane using tikz/closedcycleby katang on November 13, 2025 at 11:26 pm
I want to make a 3-D figure with a spatial diagram line and draw its projections onto the three axes planes. For better visibility, I want to mark the projections' positions with shaded planes. The MWE and the result are shown below. It looks like that \closedcycle wants to close anyhow in the plane containing the z-axis. Is there any option to draw a plane perpendicular to the z-axis (i.e., to the other two planes)? (I also tried \addplot3 [surf, fill] and fill between, but to no avail.) \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis} %XZ plane \addplot3 [fill=red!20,opacity=30,draw=none,fill opacity=0.5,] coordinates {(0,120,3900)(3,120,3900)} \closedcycle; %YZ plane \addplot3 [fill=green!20,opacity=30,draw=none,fill opacity=0.5,] coordinates {(3,-40,3900)(3,120,3900)} \closedcycle; %XY plane \addplot3 [fill=blue!20,opacity=30,draw=none,fill opacity=0.5,] coordinates {(0,-40,3900)(3,120,3900)} \closedcycle; \end{axis} \end{tikzpicture} \end{document} As a reply to @Jasper, I attach the figure here I need one more plane, for the blue diagram line. The thick spatial curve is projected to the axial planes. Thanks to all for your helpfulness and the useful hints.
- Prevent quantikz from altering tikz behaviour?by mavzolej on March 21, 2024 at 2:18 am
This code \documentclass{article} \usepackage{tikz-cd} % \usetikzlibrary{quantikz2} \begin{document} \begin{tikzcd}[ampersand replacement=\&] A \arrow[rrrr, ""] \& \& \& \& B \arrow[rd, ""] \\ \& \& \& \& \& C \\ D \arrow[rrrr, ""] \& \& \& \& E \arrow[ru] \end{tikzcd} \end{document} produces this: This code \documentclass{article} \usepackage{tikz-cd} \usetikzlibrary{quantikz2} \begin{document} \begin{tikzcd}[ampersand replacement=\&] A \arrow[rrrr, ""] \& \& \& \& B \arrow[rd, ""] \\ \& \& \& \& \& C \\ D \arrow[rrrr, ""] \& \& \& \& E \arrow[ru] \end{tikzcd} \end{document} produces this: How do I get the first result if I need to use quantikz in my document? Loading quantikz locally for each diagram seems painful.
- Beamer class: text height too large for height of footline and headline with tikz picturesby Daniel Stich on March 9, 2022 at 11:39 pm
I tried to recreate my university powerpoint template which includes images as headline and footline banner (beamer class, no predefined theme, xelatex). It seemed easier to place image plus text with tikz. When placing text in frames, text starts within the headline and violates the footline (positioning t or b). My MWE draws a box with \textheightto illustrate the problem. I found this code snippet which should somehow increase the height of the footline but it didn't solve the problem. I hope someone can help me out. Thanks! \makeatletter \patchcmd{\beamer@calculateheadfoot}{\advance\footheight by 4pt}{\advance\footheight by 20pt}{}{} \makeatother MWE: \documentclass[ presentation, %handout, 11pt, aspectratio=43, % 4:3, 128mm:96mm table, usepdftitle=false, ]{beamer} % Packages \usepackage{tikz} \usetikzlibrary{arrows, shapes.arrows, arrows.meta, positioning, fit, calc, backgrounds, patterns, 3d} % Lengths \newlength{\myLeftMargin} \newlength{\myLeftMarginText} \newlength{\myRightMargin} \newlength{\myRightMarginText} \setlength{\myLeftMargin}{0.019685\paperwidth} \setlength{\myLeftMarginText}{0.0909\paperwidth} \setlength{\myRightMargin}{\myLeftMargin} \setlength{\myRightMarginText}{\myLeftMarginText} \setbeamersize{text margin left=\myLeftMarginText} \setbeamersize{text margin right=\myRightMarginText} \setbeamersize{sidebar width left=0pt} % Headline \makeatletter \patchcmd{\beamer@calculateheadfoot}{\advance\footheight by 4pt}{\advance\footheight by 20pt}{}{} \makeatother \setbeamertemplate{headline}{% \begin{tikzpicture}[overlay, remember picture] \node[anchor=north west, inner sep=0pt] at ($(current page.north west)+(0,0)$) (nodeHeadlineBar){ \includegraphics[width=\paperwidth, height=0.15\paperheight]{example-image} }; \end{tikzpicture}% } \setbeamertemplate{frametitle}{% \begin{tikzpicture}[overlay, remember picture] \node[anchor=west, inner sep=0pt] at ($(nodeHeadlineBar.west)+(\myLeftMargin,0)$){ \insertframetitle }; \end{tikzpicture}% } \setbeamertemplate{footline}{% \begin{tikzpicture}[overlay, remember picture] \node[anchor=south west, inner sep=0pt] at ($(current page.south west)+(0,0)$) (nodeFootlineBar){ \includegraphics[width=\paperwidth, height=0.05\paperheight]{example-image} }; \node[anchor=east, inner sep=0pt] at ($(nodeFootlineBar.east)+(-\myRightMargin,0)$){ \insertframenumber\,/\,\inserttotalframenumber }; \end{tikzpicture}% } \begin{document} \section{Example 1} \begin{frame}[b]{\secname} \begin{tikzpicture} \draw[red] (0,0) rectangle (\textwidth,\textheight); \draw[red] (0,\textheight) -- (\textwidth,0) (0,0) -- (\textwidth, \textheight); \end{tikzpicture} \end{frame} \section{Example 2} \begin{frame}[t]{\secname} \begin{tikzpicture} \draw[red] (0,0) rectangle (\textwidth,\textheight); \draw[red] (0,\textheight) -- (\textwidth,0) (0,0) -- (\textwidth, \textheight); \end{tikzpicture} \end{frame} \end{document}
- Creating taxonomy diagrams that could include long textby Mr.Robot on January 24, 2022 at 3:48 pm
I am now writing a survey paper and I would like to create a taxonomy that organizes the previous works. I checked out the https://texample.net/tikz/examples/feature/trees/ but the provided templates do not seem to be applicable to my case: I need to put some (sometimes) long comments at the terminal nodes. I saw two examples that might be relevant (they are taken from paper and paper) but not sure if they come from some template I am not aware of.
- 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 can we draw a symbol like normally open/closed contacts in the tikz or latex?by Curiosity on September 7, 2020 at 5:29 am
I am facing lots of difficulty in drawing a symbol called normally open/closed conatct in tikz and latex. so I need help with drawing such a symbol and different versions of it as attached in the snip.
- 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.
- What is the approach to draw a 3-port rectangular box with tikz or circuitikzby John on August 10, 2017 at 3:40 pm
I am new to circuitikz and tikz. I have spent a few days trying to draw a circuit diagram of a direct conversion IQ transceiver. I am stuck at trying to draw a 3-port rectangular box. For example, the box with the pi/2 in it in the following graph. I searched the user manual but cannot find a three-port device. Below is the code I have been experimenting \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{tikz} \usepackage{circuitikz} \begin{document} \section{Introduction} \begin{circuitikz} \draw (5,5) node[mixer,box,anchor=east] (m) {} to[amp,box,>,-o] ++(2.5,0) (m.west) node[inputarrow] {} to[short,-o] ++(-0.8,0) (m.south) node[inputarrow,rotate=90] {} to[twoport,t=90$^{\circ}$] ++(0,-2) node[oscillator,box,anchor=north] {}; \end{circuitikz} \end{document} I would appreciate it if someone can point me to the right direction.
- Create a triangle in a block diagram with tikzby Joe on March 12, 2015 at 4:06 pm
I've been trying to create a triangle as a buffer in my diagram, but i get the error: !Package pgfkeys Error: I do no know the key '/tikz/buffer' and I am going to ignore it. Perhaps you misspelled if. Can anyone point me in the right direction. I have included the packages and tikz library: \usepackage{tikz} \usetikzlibrary{shapes,arrows} \usetikzlibrary{shapes.geometric} \tikzset{% blocks/.style = {draw, thick, rectangle, minimum height = 3em, minimum width = 3em}, sum/.style = {draw, circle, node distance = 2cm}, % Adder input/.style = {coordinate}, % Input output/.style = {coordinate} % Output %buffer/.style = {isosceles triangle, fill=gray!25, minimum width=1.5cm } buffer/.style={ draw, shape border rotate=180, regular polygon, regular polygon sides=3, fill=white, node distance=2cm, minimum height=4em } } % Defining string as labels of certain blocks. \newcommand{\suma}{\Large$+$} \newcommand{\inte}{$\displaystyle \int$} \newcommand{\derv}{\huge$\frac{d}{dt}$} \begin{center} \begin{tikzpicture}[auto, thick, node distance=2cm, >=triangle 45] \draw % Drawing the blocks of first filter : node at (0,0)[right=-3mm]{\Large \textopenbullet} node [input, name=input1] {} node [sum, right of=input1] (suma1) {\suma} node [blocks, right of=suma1] (inte1) {\Large $z^{-1}$} node [blocks, right of=inte1] (inte2) {\Large $z^{-1}$} node [buffer, right of=inte2] (buff) {\Large $K$} %node at (6,0)[block] (Q1) {\Large $z^{-1}$} %giver navn på blocken %node at (8,0)[blocks] (Q2) {\Large $K$} %node at (8,0)[buffer] (Q1) {\Large $K$} node [blocks, below of=inte1] (ret1) {\Large$T_1$}; % Joining blocks. % Commands \draw with options like [->] must be written individually \draw[->](input1) -- node {$X(n)$}(suma1); \draw[->](suma1) -- node {$+$} (inte1); \draw[->](inte1) -- node {} (inte2); %\draw[->](inte2) -- node {} {Q2}; \draw[->](ret1) -| node[near end]{} (suma1); % Adder ; \end{tikzpicture} \end{center} \begin{tikzpicture} \node [isosceles triangle, fill=gray!25, minimum width=1.5cm] (t) {}; \end{tikzpicture}
- How can I make the node order for references in TikZ not matter?by Jonathan Komar on November 22, 2014 at 3:29 pm
Question I am wondering if it is possible to make the order of nodes irrelevant, such that references work regardless of when they are mentioned...like some kind of pre-parsing of the code that creates list of all node labels. Sample Code \begin{tikzpicture}[] \node[left=1cm of server] (client) {Client}; \node (server) at (0,0) {Server}; \node[right=1cm of server] (datastorage) {Data Storage}; \end{tikzpicture} Issue The code above will not work, because the first node references a node that has not been created/instantiated yet. Is there a way to make the order not matter? Why? The reason for this is that it is easier to have my code mimic my complex diagram's workflow. (irrelevant to the question: I want to have an answer even if you find my reasoning illogical)