• How to draw a half‑sphere with 5‑degree lines along the x‑axis in TikZ/PGF?
    by AruGip on February 19, 2026 at 8:40 pm

    I found this post and I'm trying to retrieve the version shown in the image below. Does anyone know how I can get that specific version? I've checked the documentation and explored the available properties, but I couldn't find anything that returns the same value shown there. Any ideas on how to achieve this?

  • Create a directed graph
    by Dimitrios ANAGNOSTOU on February 19, 2026 at 4:15 pm

    I want to create the following figure. Using the following code, I managed to get something close. But I cannot figure out how to get properly the diagonal vectors without too much trial and error. Any ideas? Thanks a lot! \documentclass[a4paper,11pt]{article} \usepackage[T1]{fontenc} \usepackage[french]{babel} \usepackage{tikz} \usetikzlibrary{positioning,arrows.meta} \begin{document} \begin{figure}[!htpb] \centering \begin{tikzpicture}[ node distance=3cm, box/.style={draw, rectangle, minimum size=1.2cm, font=\large}, arr/.style={->, >=Stealth, thick} ] % Nodes \node[box] (1) {1}; \node[box, below=of 1] (2) {2}; \node[box, right=of 1] (3) {3}; \node[box, below=of 3] (4) {4}; % Labels n_i \node[above=3mm of 1] {$n_1=3$}; \node[above=3mm of 3] {$n_3=1$}; \node[below=3mm of 2] {$n_2=2$}; \node[below=3mm of 4] {$n_4=2$}; % Horizontal 1 <-> 3 (two parallel arrows) \draw[arr] ([yshift=4pt]1.east) -- ([yshift=4pt]3.west); \draw[arr] ([yshift=-4pt]3.west) -- ([yshift=-4pt]1.east); % Vertical left \draw[arr] (1) -- (2); % Vertical right \draw[arr] (4) -- (3); % Bottom horizontal \draw[arr] (2) -- (4); % Diagonals \draw[arr] (2) -- (3); \draw[arr] ([xshift=-4pt]4.north) -- ([xshift=4pt]1.south); \draw[arr] ([xshift=-4pt]1.south) -- ([xshift=4pt]4.north); \end{tikzpicture} \end{figure} \end{document}

  • I am trying to \protected@edef a bmatrix, and then I token.get_macro that token from Lua, so I can print it to the .tex at a later time
    by Jasper on February 19, 2026 at 3:25 pm

    I am trying to \protected@edef a bmatrix, and then I token.get_macro that token from Lua, so I can print it to the .tex at a later time. The error: WARNING: mathml missing for hash E6607B372B3A7F4DE18DB36E2B449CBD ! You can't use `\spacefactor' in math mode. \@->\spacefactor \@m {} \DocumentMetadata{ lang = en ,pdfversion = 2.0 ,pdfstandard = {UA-2} ,tagging = on } \tagpdfsetup {math/mathml/luamml/load=true} \documentclass{article} \usepackage{luacode,unicode-math,tikz} \begin{document} \makeatletter \protected@edef\COUNTDOOKU{\( \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \)} \makeatother \begin{tikzpicture} \begin{luacode*} tex.sprint( ("\\node at (0,0) {%s};") :format( token.get_macro("COUNTDOOKU") ) ) \end{luacode*} \end{tikzpicture} \end{document}

  • Is it possible to implement loop in TikZ like xypic?
    by YCH817 on February 18, 2026 at 8:54 pm

    I have tried plotting loop arrows with different sizes using xypic and tikz : \documentclass{article} \usepackage[a4paper, landscape=true]{geometry} \usepackage{graphicx} % Required for inserting images \usepackage[curve,pdf,all]{xy} \usepackage[svgnames,dvipsnames]{xcolor} \usepackage{tikz} \begin{document} $\begin{xy} (0,0)*+<5pt,3pt>[F-:<3pt>:red][F*:<3pt>:pink]{\vphantom{fg}x}="x", \ar@`{"x"+(-10,+10),"x"+(+10,+10)}^{1} \ar@`{"x"+(-20,+20),"x"+(+20,+20)}^{2} \ar@`{"x"+(-30,+30),"x"+(+30,+30)}^{3} \ar@`{"x"+(-40,+40),"x"+(+40,+40)}^{4} \ar@`{"x"+(-50,+50),"x"+(+50,+50)}^{5} \ar@`{"x"+(-60,+60),"x"+(+60,+60)}^{6} \ar@`{"x"+(+10,-10),"x"+(-10,-10)}^{1} \ar@`{"x"+(+20,-20),"x"+(-20,-20)}^{2} \ar@`{"x"+(+30,-30),"x"+(-30,-30)}^{3} \ar@`{"x"+(+40,-40),"x"+(-40,-40)}^{4} \ar@`{"x"+(+50,-50),"x"+(-50,-50)}^{5} \ar@`{"x"+(+60,-60),"x"+(-60,-60)}^{6} \end{xy}$ % --- \tikz{ \node [ draw, line width=.4pt, rounded corners=5pt, inner sep=3pt ] (x) at (0,0) {$x\vphantom{fg}$}; \foreach \i in {1,2,3,...,6} { \draw[->] (x) .. controls +(-\i,+\i) and +(+\i,+\i) .. (x) ; \draw[->] (x) .. controls +(+\i,-\i) and +(-\i,-\i) .. (x) ; }} \end{document} and here is the output : xypic : tikz : I noticed that the loop curve produced by tikz is a little bit squashed (especially the smallest curve, I think it is quite ugly -_-||), compared to the one produced by xypic. Since I am starting to use LuaLaTeX as compiling engine and I cannot use xypic with pdf option in LuaLaTex, I wonder if there is a good way to make tikz produce loop curves like the one produced by xypic. Also luamplib code is welcome.

  • uneven commutative diagram
    by mappingmoe on February 18, 2026 at 11:33 am

    I want to draw the following commutative diagram in LaTeX: I have tried tikzcd, but I think I won't work, since the rows have different size. Is there a clean way to do it? EDIT: my first approach was the following: \documentclass[a4paper]{article} \usepackage{tikz-cd} \begin{document} \begin{tikzcd} P \arrow{l}{pr} \arrow{d}{\pi} & TP \arrow{d}{T \pi}\\ I \arrow{ur}{\tilde{\gamma}} \arrow{r}{\dot{\gamma}} & M \arrow{l}{pr} & TM \end{tikzcd} \end{document}

  • What packages are useful for drawing topological surfaces? [closed]
    by Sean Wakasa on February 18, 2026 at 8:37 am

    I'm writing a mathematical paper that studies the fundamental groups of surface bundles, hence I need to create images of surfaces of genus greater than 1 with loops drawn on surface. What packages can I use to make such images? See page 8 of this paper for an example of such a surface.

  • Spacing in Tikz Heatmap
    by itc on February 17, 2026 at 6:09 pm

    I am struggling with the vertical space of my tikz heatmap. Specifically, my column labels are getting into the title of my diagram. The same is happening with the legend. I have put the MWE: \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{matrix, positioning, backgrounds} \begin{document} \begin{tikzpicture}[ font=\sffamily, cell/.style={ rectangle, minimum width=2.5cm, minimum height=1cm, draw=white, line width=0.5mm, align=center }, label/.style={ anchor=east, font=\bfseries\small }, header/.style={ anchor=south, rotate=45, font=\bfseries\small, anchor=south west } ] % Define Colors representing the score (Low, Medium, High) \definecolor{scoreLow}{HTML}{F2F2F2} % Weak/Low \definecolor{scoreMed}{HTML}{84B7D6} % Medium/Partial \definecolor{scoreHigh}{HTML}{004C6D} % Strong/High % Legend formatting \matrix [draw=none, anchor=north west] at (-4, 2) { \node [fill=scoreHigh, text=white, minimum width=1cm] {High/Strong}; & \node [anchor=west] {Jddhdhshdhshss}; \\ \node [fill=scoreMed, text=black, minimum width=1cm] {Zprororo}; & \node [anchor=west] {Trump}; \\ \node [fill=scoreLow, text=black, minimum width=1cm] {Hhdueueu}; & \node [anchor=west] {Ghsshshshs}; \\ }; % --- THE DATA MATRIX --- % Row 1: H % High Behavioural Realism [cite: 29], Low Auditability [cite: 81], Low Probability [cite: 78], High Actionability [cite: 40] \node[cell, fill=scoreHigh, text=white] (c11) at (0,0) {High}; \node[cell, fill=scoreLow, text=black] (c12) at (2.5,0) {Low}; \node[cell, fill=scoreLow, text=black] (c13) at (5,0) {Low}; \node[cell, fill=scoreLow, text=black] (c14) at (7.5,0) {Risk}; \node[cell, fill=scoreHigh, text=white] (c15) at (10,0) {High}; % Row 2: A % Low Realism, High Auditability [cite: 82], Med Probability (Rankings) [cite: 109] \node[cell, fill=scoreLow, text=black] (c21) at (0,-1) {Low}; \node[cell, fill=scoreHigh, text=white] (c22) at (2.5,-1) {High}; \node[cell, fill=scoreMed, text=black] (c23) at (5,-1) {Med}; \node[cell, fill=scoreMed, text=black] (c24) at (7.5,-1) {Med}; \node[cell, fill=scoreMed, text=black] (c25) at (10,-1) {Med}; % Row 3: B % Input oriented [cite: 112], Low actionability alone [cite: 113] \node[cell, fill=scoreLow, text=black] (c31) at (0,-2) {Low}; \node[cell, fill=scoreMed, text=black] (c32) at (2.5,-2) {Med}; \node[cell, fill=scoreLow, text=black] (c33) at (5,-2) {Low}; \node[cell, fill=scoreHigh, text=white] (c34) at (7.5,-2) {High}; \node[cell, fill=scoreLow, text=black] (c35) at (10,-2) {Low}; % Row 4: C % Easier to document [cite: 94], Explore plausibility not prob [cite: 93] \node[cell, fill=scoreMed, text=black] (c41) at (0,-3) {Med}; \node[cell, fill=scoreHigh, text=white] (c42) at (2.5,-3) {High}; \node[cell, fill=scoreLow, text=black] (c43) at (5,-3) {Low}; \node[cell, fill=scoreMed, text=black] (c44) at (7.5,-3) {Med}; \node[cell, fill=scoreMed, text=black] (c45) at (10,-3) {Med}; % Row 5: D % Traceability/Coherence [cite: 96], Probabilistic [cite: 95] \node[cell, fill=scoreLow, text=black] (c51) at (0,-4) {Low}; \node[cell, fill=scoreHigh, text=white] (c52) at (2.5,-4) {High}; \node[cell, fill=scoreHigh, text=white] (c53) at (5,-4) {High}; \node[cell, fill=scoreLow, text=black] (c54) at (7.5,-4) {Low}; \node[cell, fill=scoreMed, text=black] (c55) at (10,-4) {Med}; % Row 6: E % Normative/Pathways[cite: 101], High Actionability \node[cell, fill=scoreLow, text=black] (c61) at (0,-5) {Low}; \node[cell, fill=scoreMed, text=black] (c62) at (2.5,-5) {Med}; \node[cell, fill=scoreLow, text=black] (c63) at (5,-5) {Low}; \node[cell, fill=scoreHigh, text=white] (c64) at (7.5,-5) {High}; \node[cell, fill=scoreHigh, text=white] (c65) at (10,-5) {High}; % Row 7: F % Calibration/Monitoring[cite: 133], High Probability, Low Realism \node[cell, fill=scoreLow, text=black] (c71) at (0,-6) {Low}; \node[cell, fill=scoreHigh, text=white] (c72) at (2.5,-6) {High}; \node[cell, fill=scoreHigh, text=white] (c73) at (5,-6) {High}; \node[cell, fill=scoreLow, text=black] (c74) at (7.5,-6) {Low}; \node[cell, fill=scoreMed, text=black] (c75) at (10,-6) {Med}; % Row 8: G % Adversarial[cite: 122], Low Auditability (often anecdotal) \node[cell, fill=scoreHigh, text=white] (c81) at (0,-7) {High}; \node[cell, fill=scoreLow, text=black] (c82) at (2.5,-7) {Low}; \node[cell, fill=scoreLow, text=black] (c83) at (5,-7) {Low}; \node[cell, fill=scoreLow, text=black] (c84) at (7.5,-7) {Low}; \node[cell, fill=scoreMed, text=black] (c85) at (10,-7) {Med}; % --- LABELS --- % Y-Axis Labels (Methods) \node[label] at (-1.5, 0) {H}; \node[label] at (-1.5, -1) {A}; \node[label] at (-1.5, -2) {B}; \node[label] at (-1.5, -3) {C}; \node[label] at (-1.5, -4) {D}; \node[label] at (-1.5, -5) {E}; \node[label] at (-1.5, -6) {F}; \node[label] at (-1.5, -7) {G}; % X-Axis Labels (Attributes) \node[header] at (0, 0.6) {Fuuueueueu djejejejjejejejejej}; \node[header] at (2.5, 0.6) {Ldhdhdhdd hdhdjddjdjdjdjeieeieiidjd}; \node[header] at (5, 0.6) {LLwhwuquahsajqjqjqjqjqqjssjsj}; \node[header] at (7.5, 0.6) {Kahhwuwuwuddeeicdjsjwjw}; \node[header] at (10, 0.6) {KKsiwiwiwiwyduweueeuee}; % Title \node[anchor=center, font=\bfseries\Large] at (3.5, 3.5) {Xfhfhhe jeeieiei nddjewoo djwiwoxdk msaaakkkwifjfjf}; \node[anchor=center, font=\small, text width=12cm, align=center] at (3.5, 2.8) {Xomtive fhfru dieieo difiwwi dkdfjdkwo ksksskskw.\\ \textit{Fsw7w8 ddijej doofoe cdirirfv iiroflvw dkoeowoxk dfeke.}}; \end{tikzpicture} \end{document} I have attached the screenshot as well:

  • Introducing a vertical line in a quantikz circuit
    by Rob on February 17, 2026 at 10:44 am

    I have the following circuit generated using quantikz: \documentclass{article} \usepackage{quantikz} \begin{document} \begin{center} \begin{quantikz}[row sep=.2cm, column sep=.5cm] \lstick{$|0\rangle$} & \gate{A} & \gate[2]{B} & \ghost{C} & \gate{D} & \\ \lstick{$|1\rangle$} & & & \gate[2]{C} & \gate{E} & \\ \lstick{$|1\rangle$} & & & & \gate{F} & \end{quantikz} \end{center} \end{document} How can I introduce some vertical lines as shown in the attached screenshot below

  • Why does an error occur if I replace the code with the one that uses "foreach"?
    by Paco Robledo on February 16, 2026 at 1:19 pm

    \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{amsmath} % <- \text{} erabiltzeko beharrezkoa \begin{document} \begin{tikzpicture}[transform shape] %horizontal projection %variable definitions \def\g{-9.8} %gravity \def\v{10} %velocity \def\ang{51} %angle \def\s{0.1} \pgfmathsetmacro{\c}{{(-1*(2/\g)*\v*sin(\ang))/2}} \begin{axis}[ width=.45\linewidth, %set bigger width height=2.2in, xmin={{\v*cos(\ang)*\c}},xmax=11.5, ymin=0,ymax={\v*\c*sin(\ang)+0.5*\g*(\c^2)},, xlabel=$x$, ylabel=$600 m$, axis x line = bottom, axis y line = left, y axis line style={-}, ticks = none,clip=false, ] \tikzset{every mark/.append style={fill=white}} %flight path \addplot[ dashed, domain={\v*cos(\ang)*\c}:10, samples=100,] {{\g*(x^2)/(2*\v^2*cos(\ang)^2)+x*tan(\ang)}}; %flight path \addplot[ dashed, domain=5:10, samples=100,] {{\v*\c*sin(\ang)+0.5*\g*(\c^2)}}; %vector at end \pgfmathsetmacro{\a}{{-1*(2/\g)*\v*sin(\ang)}} \coordinate (E) at (axis cs:{\v*cos(\ang)*\a},{\v*\a*sin(\ang)+0.5*\g*(\a^2)}){}; \coordinate (F) at (axis cs:{\v*cos(\ang)*\a+\s*\v*cos(\ang))}, {\v*\a*sin(\ang)+0.5*\g*\a^2+\s*(\v*sin(\ang)+\g*\a)}); \coordinate (G) at (axis cs:{\v*cos(\ang)*\a},{\v*\c*sin(\ang)+0.5*\g*(\c^2)}); \draw[very thick,->](E)--(F) node[right, at end,font=\tiny]{$\vec{V}$}; \draw[very thick,->](G)--(F |- G) node[midway,above,font=\tiny]{$\vec{V}$}; \draw[densely dashed,very thick,->](E)--(F |- E) node[midway,above,font=\tiny]{$\vec{V}_x$}; \draw[densely dashed,very thick,->](E)--(F-| E) node[midway,left,font=\tiny]{$\vec{V}_y$}; \path plot[mark=*] coordinates {(E)}; \path plot[mark=*] coordinates {(G)}; %vector at start \pgfmathsetmacro{\c}{{(-1*(2/\g)*\v*sin(\ang))/2}} \coordinate (L) at (axis cs:{\v*cos(\ang)*\c},{\v*\c*sin(\ang)+0.5*\g*(\c^2)}); \coordinate (M) at (axis cs:{\v*cos(\ang)*\c+\s*\v*cos(\ang))},{\v*\c*sin(\ang)+0.5*\g*\c^2+\s*(\v*sin(\ang)+\g*\c)}); \draw[very thick,->](L)--(M) node[midway,sloped,above,font=\tiny]{$\vec{V}$}; \path plot[mark=*] coordinates {(L)}; %vector 1/2 down \pgfmathsetmacro{\d}{{(-1*(2/\g)*\v*sin(\ang))*0.75}} \coordinate (P) at (axis cs:{\v*cos(\ang)*\d},{\v*\d*sin(\ang)+0.5*\g*(\d^2)}); \coordinate (Q) at (axis cs:{(\v*cos(\ang)*\d+\s*\v*cos(\ang))},{\v*\d*sin(\ang)+0.5*\g*\d^2+\s*(\v*sin(\ang)+\g*\d)}); \coordinate (O) at (axis cs:{\v*cos(\ang)*\d},{\v*\c*sin(\ang)+0.5*\g*(\c^2)}); \draw[very thick,->](P)--(Q) node[right, at end,font=\tiny]{$\vec{V}$}; \draw[very thick,->](O)--(Q |- O) node[midway,above,font=\tiny]{$\vec{V}$}; \draw[densely dashed,very thick,->](P)--(Q|-P) node[midway,above,font=\tiny]{$\vec{V}_x$}; \draw[densely dashed,very thick,->](P)--(Q-|P) node[midway,left,font=\tiny]{$\vec{V}_y$}; \path plot[mark=*] coordinates {(P)}; \path plot[mark=*] coordinates {(O)}; %vector 3/4 down \pgfmathsetmacro{\f}{{(-1*(2/\g)*\v*sin(\ang))*0.6}} \coordinate (R) at (axis cs:{\v*cos(\ang)*\f},{\v*\f*sin(\ang)+0.5*\g*(\f^2)}); \coordinate (S) at (axis cs:{(\v*cos(\ang)*\f+\s*\v*cos(\ang))},{\v*\f*sin(\ang)+0.5*\g*\f^2+\s*(\v*sin(\ang)+\g*\f)}); \coordinate (V) at (axis cs:{\v*cos(\ang)*\f},{\v*\c*sin(\ang)+0.5*\g*(\c^2)}); \draw[very thick,->](R)--(S) node[right, at end,font=\tiny]{$\vec{V}$}; \draw[very thick,->](V)--(S |- V) node[midway,above,font=\tiny]{$\vec{V}$}; \draw[densely dashed,very thick,->](R)--(S|-R) node[right, at end,font=\tiny]{$\vec{V}_x$}; \draw[densely dashed,very thick,->](R)--(S-|R) node[at end,below,font=\tiny]{$\vec{V}_y$}; \path plot[mark=*] coordinates {(R)}; \path plot[mark=*] coordinates {(V)}; %vector 1/4 down \pgfmathsetmacro{\e}{{(-1*(2/\g)*\v*sin(\ang))*0.875}} \coordinate (T) at (axis cs:{\v*cos(\ang)*\e},{\v*\e*sin(\ang)+0.5*\g*(\e^2)}); \coordinate (U) at (axis cs:{(\v*cos(\ang)*\e+\s*\v*cos(\ang))},{\v*\e*sin(\ang)+0.5*\g*\e^2+\s*(\v*sin(\ang)+\g*\e)}); \coordinate (W) at (axis cs:{\v*cos(\ang)*\e},{\v*\c*sin(\ang)+0.5*\g*(\c^2)}); \draw[very thick,->](T)--(U) node[right, at end,font=\tiny]{$\vec{V}$}; \draw[very thick,->](W)--(U |- W) node[midway,above,font=\tiny]{$\vec{V}$}; \draw[densely dashed,very thick,->](T)--(U|-T) node[midway,above,font=\tiny]{$\vec{V}_x$}; \draw[densely dashed,very thick,->](T)--(U-|T) node[midway,left,font=\tiny]{$\vec{V}_y$}; \path plot[mark=*] coordinates {(T)}; \path plot[mark=*] coordinates {(W)}; \end{axis} \end{tikzpicture} \end{document} With foreach: \begin{tikzpicture}[transform shape] %horizontal projection %variable definitions \def\g{-9.8} %gravity \def\v{10} %velocity \def\ang{51} %angle \def\s{0.1} \pgfmathsetmacro{\c}{{(-1*(2/\g)*\v*sin(\ang))/2}} \begin{axis}[ width=.45\linewidth, %set bigger width height=2.2in, xmin={{\v*cos(\ang)*\c}},xmax=11.5, ymin=0,ymax={\v*\c*sin(\ang)+0.5*\g*(\c^2)},, xlabel=$x$, ylabel=$600 m$, axis x line = bottom, axis y line = left, y axis line style={-}, ticks = none,clip=false, ] \tikzset{every mark/.append style={fill=white}} %flight path \addplot[ dashed, domain={\v*cos(\ang)*\c}:10, samples=100,] {{\g*(x^2)/(2*\v^2*cos(\ang)^2)+x*tan(\ang)}}; %flight path \addplot[ dashed, domain=5:10, samples=100,] {{\v*\c*sin(\ang)+0.5*\g*(\c^2)}}; %vector at end \pgfmathsetmacro{\a}{{-1*(2/\g)*\v*sin(\ang)}} \coordinate (E) at (axis cs:{\v*cos(\ang)*\a},{\v*\a*sin(\ang)+0.5*\g*(\a^2)}){}; \coordinate (F) at (axis cs:{\v*cos(\ang)*\a+\s*\v*cos(\ang))}, {\v*\a*sin(\ang)+0.5*\g*\a^2+\s*(\v*sin(\ang)+\g*\a)}); \coordinate (G) at (axis cs:{\v*cos(\ang)*\a},{\v*\c*sin(\ang)+0.5*\g*(\c^2)}); \draw[very thick,->](E)--(F) node[right, at end,font=\tiny]{$\vec{V}$}; \draw[very thick,->](G)--(F |- G) node[midway,above,font=\tiny]{$\vec{V}$}; \draw[densely dashed,very thick,->](E)--(F |- E) node[midway,above,font=\tiny]{$\vec{V}_x$}; \draw[densely dashed,very thick,->](E)--(F-| E) node[midway,left,font=\tiny]{$\vec{V}_y$}; \path plot[mark=*] coordinates {(E)}; \path plot[mark=*] coordinates {(G)}; %vector at start \pgfmathsetmacro{\c}{{(-1*(2/\g)*\v*sin(\ang))/2}} \coordinate (L) at (axis cs:{\v*cos(\ang)*\c},{\v*\c*sin(\ang)+0.5*\g*(\c^2)}); \coordinate (M) at (axis cs:{\v*cos(\ang)*\c+\s*\v*cos(\ang))},{\v*\c*sin(\ang)+0.5*\g*\c^2+\s*(\v*sin(\ang)+\g*\c)}); \draw[very thick,->](L)--(M) node[midway,sloped,above,font=\tiny]{$\vec{V}$}; \path plot[mark=*] coordinates {(L)}; \foreach \terd in {0.6,0.75,0.875} { \pgfmathsetmacro{\d}{{(-1*(2/\g)*\v*sin(\ang))*\terd}} \coordinate (P) at (axis cs:{\v*cos(\ang)*\d},{\v*\d*sin(\ang)+0.5*\g*(\d^2)}); \coordinate (Q) at (axis cs:{(\v*cos(\ang)*\d+\s*\v*cos(\ang))},{\v*\d*sin(\ang)+0.5*\g*\d^2+\s*(\v*sin(\ang)+\g*\d)}); \coordinate (O) at (axis cs:{\v*cos(\ang)*\d},{\v*\c*sin(\ang)+0.5*\g*(\c^2)}); \draw[very thick,->](P)--(Q) node[right, at end,font=\tiny]{$\vec{V}$}; \draw[very thick,->](O)--(Q |- O) node[midway,above,font=\tiny]{$\vec{V}$}; \draw[densely dashed,very thick,->](P)--(Q|-P) node[midway,above,font=\tiny]{$\vec{V}_x$}; \draw[densely dashed,very thick,->](P)--(Q-|P) node[midway,left,font=\tiny]{$\vec{V}_y$}; \path plot[mark=*] coordinates {(P)}; \path plot[mark=*] coordinates {(O)}; } \end{axis} \end{tikzpicture}

  • TikZ forest: custom vdots keys overrides custom l sep and s sep keyvals
    by Grass on February 15, 2026 at 3:12 am

    The Problem From cfr's answer to my previous question, I managed to draw nice vdots in my forest tree. But now for tree={ s sep=1cm, % example of 1cm for illustrative purposes; you probably wouldn't want it to be so big l sep=1cm }, fails to be applied across the entire tree: Attempt(s) To Fix Said Problem I tried messing with before computing xy={% l'=0pt, s'=-15pt, % length of vdots }, but it didn't really work. What Help I need I've only had very modest experience with forest so I'm having trouble deducing how to modifiy cfr's code, such that the keyvals s sep and l sep work correctly. Thus, it would be nice if someone was able to help me out with this. MWE: % Source - https://tex.stackexchange.com/a/755401 % Posted by cfr, modified by community. See post 'Timeline' for change history % Retrieved 2026-02-14, License - CC BY-SA 4.0 \documentclass[border=10pt,multi,tikz]{standalone} % ateb: https://tex.stackexchange.com/a/754955/ % ateb: https://tex.stackexchange.com/a/755401/ \usepackage[edges]{forest} \usetikzlibrary{calc} \definecolor{folderbg}{RGB}{124,166,198} \definecolor{folderborder}{RGB}{110,144,169} \newlength\Size \setlength\Size{4pt} \tikzset{% folder/.pic={% \draw [draw=folderborder, sharp corners, top color=folderbg!50, bottom color=folderbg ] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \draw [draw=folderborder, sharp corners, top color=folderbg!50, bottom color=folderbg ] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, sharp corners, 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, declare keylist={additional edge options}{}, 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}, } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %===========================================% \makeatletter \def\dirtree@dot@radius{0.5pt} \def\dirtree@vdots@length{5pt} \forestset{% declare toks={real siblings}{}, continue/.style={% delay={% if n children=0{% before computing xy={% for current and following siblings={% s'+=-10pt, }, }, if n=1{% edge path'={% (!u.parent anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ($(!u.parent anchor -| a)!1/3!(.child anchor -| a)$) edge [dotted] ($(!u.parent anchor -| a)!2/3!(.child anchor -| a)$) ($(!u.parent anchor -| a)!2/3!(.child anchor -| a)$) |- (.child anchor) }, }{% edge path'={% (!u.parent anchor |- !p.child anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ($(!p.child anchor -| a)!1/3!(.child anchor -| a)$) edge [dotted] ($(!p.child anchor -| a)!2/3!(.child anchor -| a)$) ($(!p.child anchor -| a)!2/3!(.child anchor -| a)$) |- (.child anchor) }, }, for following siblings={% edge path'={% (!u.parent anchor |- !p.child anchor) ++(\foresteregister{folder indent},0pt) |- (.child anchor) }, }, }{% 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'=-\dirtree@vdots@length, % length of vdots }, delay n=2{% split option={real siblings}{,}{append}, }, before typesetting nodes={% temptoksa/.option=name, delay={ do dynamics, for children={ if n=1{ edge path'={% (!uu.parent anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ($($(a)!1/2!(.child anchor -| a)$)+0.5*(0,\dirtree@vdots@length)$) coordinate (A\foresteoption{id}) % ($($(a)!1/2!(.child anchor -| a)$)-0.5*(0,\dirtree@vdots@length)$) coordinate (B\foresteoption{id}) |- (.child anchor)% }, tikz+={ \coordinate (A') at ($(A\foresteoption{id})+(0,\dirtree@dot@radius)$); \coordinate (B') at ($(B\foresteoption{id})-(0,\dirtree@dot@radius)$); \coordinate (C) at ($0.25*($(B')-(A')$)$); \fill ($(A')+(C)$) circle (\dirtree@dot@radius); \fill ($(A')+2*(C)$) circle (\dirtree@dot@radius); \fill ($(A')+3*(C)$) circle (\dirtree@dot@radius); }, }{ edge path'={% (!uu.parent anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) (a |- !p.child anchor) |- (.child anchor) }, }, }, }, }, }, no edge, ]}, }, }, }, to be continued/.style={% delay={% append={[\strut, folder, grow'=0, before computing xy={% l'=0pt, s'=0pt, }, 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) -- (.parent anchor -| a) coordinate (A\foresteoption{id}) % ([yshift=-\dirtree@vdots@length]% length of vdots A\foresteoption{id}) coordinate (B\foresteoption{id}) }, tikz+={ \coordinate (A') at ($(A\foresteoption{id})+(0,\dirtree@dot@radius)$); \coordinate (B') at ($(B\foresteoption{id})-(0,\dirtree@dot@radius)$); \coordinate (C) at ($0.25*($(B')-(A')$)$); \fill ($(A')+(C)$) circle (\dirtree@dot@radius); \fill ($(A')+2*(C)$) circle (\dirtree@dot@radius); \fill ($(A')+3*(C)$) circle (\dirtree@dot@radius); }, ]}, }, }, } \makeatother %===========================================% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, s sep=1cm, l sep=1cm }, [system [config ] [lib [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, s sep=1cm, l sep=1cm }, [system, continue [config ] [lib, to be continued [file.txt, file, to be continued ] ] ] \end{forest} \end{document}

  • TikZ forest: evenly spaced vertical dots in directory tree
    by Grass on February 14, 2026 at 3:10 pm

    I modified cfr's previous answer to draw three evenly spaced vertical dots. A sketch of the desired look is as follows, where the blue line is imaginary (only there for illustrative purposes) and should not be actually drawn by TikZ. But, only one set of my custom vdots are drawn by TikZ. Any idea how to fix this? I tried appending the node names (e.g. (A)) with a counter ((A \the<counter_name>)) that is incremented with each invocation of vdots. But that didn't seem to work at all. MWE: % Source - https://tex.stackexchange.com/a/755401 % Posted by cfr, modified by community. See post 'Timeline' for change history % Retrieved 2026-02-14, License - CC BY-SA 4.0 \documentclass[border=10pt,multi,tikz]{standalone} % ateb: https://tex.stackexchange.com/a/754955/ % ateb: https://tex.stackexchange.com/a/755401/ \usepackage[edges]{forest} \usetikzlibrary{calc} \definecolor{folderbg}{RGB}{124,166,198} \definecolor{folderborder}{RGB}{110,144,169} \newlength\Size \setlength\Size{4pt} \tikzset{% folder/.pic={% \draw [draw=folderborder, sharp corners, top color=folderbg!50, bottom color=folderbg ] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \draw [draw=folderborder, sharp corners, top color=folderbg!50, bottom color=folderbg ] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, sharp corners, 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, declare keylist={additional edge options}{}, 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}, } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %===========================================% \makeatletter \def\dirtree@dot@radius{1pt} \forestset{% declare toks={real siblings}{}, vdots@root/.style={% delay={% if n children=0{% before computing xy={% for current and following siblings={% s'+=-10pt, }, }, if n=1{% edge path'={% (!u.parent anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ($(!u.parent anchor -| a)!1/3!(.child anchor -| a)$) edge [dotted] ($(!u.parent anchor -| a)!2/3!(.child anchor -| a)$) ($(!u.parent anchor -| a)!2/3!(.child anchor -| a)$) |- (.child anchor) }, }{% edge path'={% (!u.parent anchor |- !p.child anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ($(!p.child anchor -| a)!1/3!(.child anchor -| a)$) edge [dotted] ($(!p.child anchor -| a)!2/3!(.child anchor -| a)$) ($(!p.child anchor -| a)!2/3!(.child anchor -| a)$) |- (.child anchor) }, }, for following siblings={% edge path'={% (!u.parent anchor |- !p.child anchor) ++(\foresteregister{folder indent},0pt) |- (.child anchor) }, }, }{% 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}, }, before typesetting nodes={% temptoksa/.option=name, delay={ do dynamics, for children={ if n=1{ edge path'={% (!uu.parent anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ($(a)!1/3!(.child anchor -| a)$) coordinate (A) % ($(a)!2/3!(.child anchor -| a)$) coordinate (B) % ($(a)!2/3!(.child anchor -| a)$) |- (.child anchor)% }, tikz+={ \coordinate (A') at ($(A)+(0,\dirtree@dot@radius)$); \coordinate (B') at ($(B)-(0,\dirtree@dot@radius)$); \coordinate (C) at ($0.25*($(B')-(A')$)$); % Debugging % \draw[blue] ($(A')-(5pt,0)$) -- ($(A')+(5pt,0)$); % \draw[red] ($(A')+(C)-(5pt,0)$) -- ($(A')+(C)+(5pt,0)$); % \draw[red] ($(A')+2*(C)-(5pt,0)$) -- ($(A')+2*(C)+(5pt,0)$); % \draw[red] ($(A')+3*(C)-(5pt,0)$) -- ($(A')+3*(C)+(5pt,0)$); % \draw[red] ($(A')+4*(C)-(5pt,0)$) -- ($(A')+4*(C)+(5pt,0)$); % \draw[blue] ($(B')-(5pt,0)$) -- ($(B')+(5pt,0)$); \fill ($(A')+(C)$) circle (\dirtree@dot@radius); \fill ($(A')+2*(C)$) circle (\dirtree@dot@radius); \fill ($(A')+3*(C)$) circle (\dirtree@dot@radius); }, }{ edge path'={% (!uu.parent anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) (a |- !p.child anchor) |- (.child anchor) }, }, }, }, }, }, no edge, ]}, }, }, }, vdots@others/.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'={% ([xshift=\forestregister{folder indent}]!uu.parent anchor) coordinate (a) -- ([yshift=9pt].parent anchor -| a) coordinate (A) % (.parent anchor -| a) coordinate (B) }, tikz+={ \coordinate (A') at ($(A)+(0,\dirtree@dot@radius)$); \coordinate (B') at ($(B)-(0,\dirtree@dot@radius)$); \coordinate (C) at ($0.25*($(B')-(A')$)$); \fill ($(A')+(C)$) circle (\dirtree@dot@radius); \fill ($(A')+2*(C)$) circle (\dirtree@dot@radius); \fill ($(A')+3*(C)$) circle (\dirtree@dot@radius); }, ]}, }, }, vdots/.style={ if level = 0{vdots@root}{vdots@others} } } \makeatother %===========================================% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,vdots [config ] [lib,vdots [Access, vdots ] [Plugin, vdots ] [file.txt, file,vdots ] ] ] \end{forest} \end{document}

  • Strange geometric calculation error of ellipse with `arc` in tikz?
    by Explorer on February 14, 2026 at 7:33 am

    I want to plot something as below in an elegant appraoch, with a handy control of the angle and eccentricity: (the pattern is not important here) Here below, I make some calculations: \documentclass[tikz,border=5pt]{standalone} \begin{document} \begin{tikzpicture}[line join=round] \def\R{5} \def\ell{0.9} \def\startAngle{40} \def\endAngle{90-\startAngle} \def\rhoo{\fpeval{\R*sind(45-\startAngle)/cosd(\startAngle)}} \def\Rx{\fpeval{\rhoo*(sqrt(1-(\ell^2*cosd(\startAngle)^2)))/(sqrt(1-\ell^2))}} \def\Ry{\fpeval{\Rx*(sqrt(1-\ell^2))}} \def\ellstartAngle{\fpeval{atand(\Rx/\Ry*tand(\startAngle))}} \filldraw[ fill=cyan!30, draw=cyan, very thick ] (\R,0) arc[start angle=0, end angle=\startAngle, radius=\R] { [rotate=-\startAngle] arc[start angle=-\ellstartAngle,end angle=180+\ellstartAngle,x radius=\Rx,y radius=\Ry] } arc[start angle=\endAngle, end angle=90, radius=\R] -- (0,\R) -- (\R,\R) -- cycle; \end{tikzpicture} \end{document} But it gives some drawbacks of the ellipse's ending tip: With the following sketch: My calculation thoughts is as below: noted that \StartAngle is \theta, and \ell is the ellipse's eccentricity with \def\rhoo{\fpeval{\R*sind(45-\startAngle)/cosd(\startAngle)}}, I want to derive the radius from origin of the ellipse, that is the \rho's distance in the sketch with the formula of the radius length from origin of the ellipse, that is: I want to derive the x-radius of ellipse, that is a(\Rx) via \def\Rx{\fpeval{\rhoo*(sqrt(1-(\ell^2*cosd(\startAngle)^2)))/(sqrt(1-\ell^2))}} Then I calaulated the y-radius with \Rx and \ell via \def\Ry{\fpeval{\Rx*(sqrt(1-\ell^2))}} Finally, I calculate the geometric angle of sub-path rotation learning from this answer via \def\ellstartAngle{\fpeval{atand(\Rx/\Ry*tand(\startAngle))}} I really have no idea of any mathematical calculation issues or just my tikz's parameter misunderstandings. Could somebosy give me a hand? (Any approach with neat syntax are all welcome! My calculation above is just to draw this in one \path)

  • Any better suggestions with the pos of arrow on arc with tikz?
    by Explorer on February 13, 2026 at 12:25 pm

    This question is similar to this link, but not exactly the same focues. What I want, is something like: But I want a better looking and better syntax of the arrow: The figure above is produced by: \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{bending,decorations.markings,arrows.meta,calc,spath3} \usepackage{amsmath} \begin{document} \begin{tikzpicture}[ >={Kite[inset=0pt,length=.32cm,bend]}, baz/.style={spath/save=curve}, foo/.style={ draw,tips=true,->, spath/remove empty components={curve}, spath/split at keep start={curve}{#1}, spath/use=curve }, foo/.default=0.5, ] \filldraw[thick,fill=gray!40] (4,0) node[below]{$R$} arc (0:180:4) node[below]{$-R$} -- (-3,0) arc(180:0:1) -- (1,0) arc(180:0:1) -- cycle; \path[baz] (4,0) arc (0:90:4);\path[foo=.4]; \path[baz] (0,4) arc (90:180:4);\path[foo]; \path[baz] (-3,0) arc (180:0:1);\path[foo=.55]; \path[baz] (1,0) arc (180:0:1);\path[foo=.55]; \draw[-Stealth] (-5,0) -- (5,0) node[below]{$\Re$}; \draw[-Stealth] (0,0) -- (0,5) node[right]{$\Im$}; \path node[below] {$O$} (60:4) node[above=3pt] {$C_{R}$}; \end{tikzpicture} \end{document} which learning from Andrew Stacey's elegant solution. However, the code above is manually seperated, my \foreach version didn't get expected result: \documentclass[tikz,border=5pt]{standalone} % https://tex.stackexchange.com/a/656167/322482 \usetikzlibrary{bending,decorations.markings,arrows.meta,calc,spath3} \usepackage{amsmath} \begin{document} \begin{tikzpicture}[>={Kite[inset=0pt,length=.32cm,bend]}] \filldraw[ thick,fill=gray!40, spath/save=curve, ] (4,0) node[below]{$R$} arc (0:180:4) node[below]{$-R$} -- (-3,0) arc(180:0:1) -- (1,0) arc(180:0:1) -- cycle; \foreach \pos in {.1,.4,.675,.9}{% \path[ draw=blue,tips=true,->, spath/clone={tmp}{curve}, spath/remove empty components={tmp}, spath/split at keep start={tmp}{\pos}, spath/use=tmp, ]; } \draw[-Stealth] (-5,0) -- (5,0) node[below]{$\Re$}; \draw[-Stealth] (0,0) -- (0,5) node[right]{$\Im$}; \path node[below] {$O$} (60:4) node[above=3pt] {$C_{R}$}; \end{tikzpicture} \end{document} Edited: (I seemed to find some out-of-my-intuition features with spath3 and also reported at here, but actually turn out to be my fault of understanding the pos parameter of curve).

  • Table with pgfplots and title boxes across the entire textwidth
    by cis on February 13, 2026 at 10:16 am

    I want to use the entire \textwidth at a table, so I chose tabularx. The table contains plots (all the same size) and boxes with titles that contain varying amounts of text or lines. The "title boxes" should all be top-aligned, all have the same width and for each row (!) the same height. This means that the "title boxes" in row 1 have the same height, and those in row 3 also have the same height; but possibly a different height than in row 1. What's the best way to configure this? I've put the "title boxes" also into tabularx tables; but perhaps multirow would be more suitable here (?). I often have problems with overfull / underfull hbox warnings here. I don't know what the ideal solution for this. Note: I plan to disable the main table's rules later; I've set \setlength\arrayrulewidth{2pt} here to better visualize the dimensions. \documentclass[paper=a5]{scrarticle} \usepackage[margin=14mm, showframe]{geometry} \usepackage{tabularx} % \usepackage{multirow}% needed? \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{lipsum}% dummy text \newcommand\mytitle[1]{% {\begin{tabularx}{\linewidth}{|X|} \hline #1 \\ \hline \end{tabularx}} } \newcommand\myplot[1]{% \begin{tikzpicture}[baseline] \begin{axis}[width=\linewidth, height=30mm] \addplot[#1, mark=*]{x^4}; \end{axis} \end{tikzpicture}} \newcolumntype{Y}{% hspaces should be as small as possible @{\hspace{1.5pt}}X@{\hspace{1.5pt}}} \setlength\arrayrulewidth{2pt}% to see the effects \begin{document} \noindent\begin{tabularx}{\textwidth}{| Y | Y |} % Title 1 (row 1, column 1) ================== \mytitle{Title 1: \lipsum[1][1-2]} % Title 2 (row 1, column 2) ================== & \mytitle{Title 2: \lipsum[1][1]} \\ % Plot 1 (row 2, column 1) ================== \myplot{brown} % Plot 2 (row 2, column 2) ================== & \myplot{red} \\ \hline % Title 3 (row 3, column 1) ================== \mytitle{Title 3: \lipsum[1][2]} % Title 4 (row 3, column 2) ================== & \mytitle{Title 4: \lipsum[1][1-4]} \\ % Plot 3 (row 4, column 1) ================== \myplot{blue} % Plot 4 (row 4, column 2) ================== & \myplot{orange} \\ \end{tabularx} \end{document}

  • tikz draw of solid effect of stack of unit cube legos: for mathlinks
    by Epa on February 4, 2026 at 8:06 am

    How to make the solid effect view better, as shown in the photo attached? \documentclass[]{standalone} \usepackage{amsmath, amssymb, latexsym, amscd, amsthm} \usepackage{tikz} \newcommand{\drawboxa}[4]{ \pgfmathsetmacro \angle {30} \pgfmathsetmacro \xd {{2/3*cos(\angle)}} \pgfmathsetmacro \yd {{2/3*sin(\angle)}} \pgfmathsetmacro \x {{#1-1+(#2-1)*(\xd)}} \pgfmathsetmacro \y {{#3-1+(#2-1)*(\yd)}} \draw[fill=#4] (\x,\y) -- (\x+1,\y) -- (\x+1,\y+1) -- (\x,\y+1) -- cycle; \draw[fill=#4] (\x,\y+1) -- (\x+\xd,\y+1+\yd)coordinate[pos=.5](M) -- (\x+1+\xd,\y+1+\yd) -- (\x+1,\y+1) -- cycle; \draw[fill=#4] (\x+1,\y+1) -- (\x+1+\xd,\y+1+\yd) -- (\x+1+\xd,\y+\yd)coordinate[pos=.5](M2) -- (\x+1,\y)-- (\x+1,\y+1)coordinate[pos=.5](M3); \path(M2)--(M3)coordinate[pos=.5](M4); \draw[fill=#4] (M)++(.5,0)coordinate(T1)++(.15,0)arc(0:-180:.15cm and .06cm)--++(0,.1)arc(-180:0:.15cm and .06cm)coordinate(T2)--++(0,-.1) (T2)arc(0:180:.15cm and .06cm); \draw[fill=black,opacity=.1](M4)circle(.12cm and .15cm) (\x,\y)++(.5,.5)circle(.15); \draw(M4)circle(.12cm and .15cm) (\x,\y)++(.5,.5)circle(.15); } \newcommand{\drawboxb}[3]{ \pgfmathsetmacro \angle {30} \pgfmathsetmacro \xd {{2/3*cos(\angle)}} \pgfmathsetmacro \yd {{2/3*sin(\angle)}} \pgfmathsetmacro \x {{#1-1+(#2-1)*(\xd)}} \pgfmathsetmacro \y {{#3-1+(#2-1)*(\yd)}} \draw[fill=white] (\x,\y) -- (\x+1,\y) -- (\x+1,\y+1) -- (\x,\y+1) -- cycle; \draw[fill=white] (\x,\y+1) -- (\x+\xd,\y+1+\yd)coordinate[pos=.5](M) -- (\x+1+\xd,\y+1+\yd) -- (\x+1,\y+1) -- cycle; \draw[fill=white] (\x+1,\y+1) -- (\x+1+\xd,\y+1+\yd) -- (\x+1+\xd,\y+\yd)coordinate[pos=.5](M2) -- (\x+1,\y)-- (\x+1,\y+1)coordinate[pos=.5](M3); \path(M2)--(M3)coordinate[pos=.5](M4); \draw[fill=white] (M)++(.55,0)coordinate(T1)++(.15,0)arc(0:-180:.2cm and .07cm)--++(0,.1)arc(-180:0:.2cm and .07cm)coordinate(T2)--++(0,-.1) (T2)arc(0:180:.2cm and .07cm) (T2)++(-.2,0)circle(.16cm and .04cm); \draw(M4)circle(.15cm and .2cm)circle(.11cm and .16cm) (\x,\y)++(.5,.5)circle(.2)circle(.15); } \usepackage{tikzbricks} %\printanswers \newcommand{\drawboxc}[4]{ \pgfmathsetmacro \angle {30} \pgfmathsetmacro \xd {{2/3*cos(\angle)}} \pgfmathsetmacro \yd {{2/3*sin(\angle)}} \pgfmathsetmacro \x {{#1-1+(#2-1)*(\xd)}} \pgfmathsetmacro \y {{#3-1+(#2-1)*(\yd)}} \draw[fill=#4] (\x,\y) -- (\x+1,\y) -- (\x+1,\y+1) -- (\x,\y+1) -- cycle; \draw[fill=#4] (\x,\y+1) -- (\x+\xd,\y+1+\yd)coordinate[pos=.5](M) -- (\x+1+\xd,\y+1+\yd) -- (\x+1,\y+1) -- cycle; \draw[fill=#4] (\x+1,\y+1) -- (\x+1+\xd,\y+1+\yd) -- (\x+1+\xd,\y+\yd)coordinate[pos=.5](M2) -- (\x+1,\y)-- (\x+1,\y+1)coordinate[pos=.5](M3); \path(M2)--(M3)coordinate[pos=.5](M4)coordinate[pos=.4](M5); \draw[fill=#4](M4)circle(.12cm and .15cm)++(0,.15)coordinate(Y1)++(0,-.15)coordinate(Y2); \draw[fill=#4](M5)++(0,-.025)circle(.12cm and .15cm)++(0,.15)coordinate(Y3)++(0,-.3)coordinate(Y4) (Y3)--(Y1)arc(90:270:.12cm and .15cm)--(Y4)arc(270:90:.12cm and .15cm); \draw[fill=black,opacity=.1](\x,\y)++(.5,.5)circle(.15) (M)++(.5,0)coordinate(T1)circle(.15cm and .06cm); \draw(\x,\y)++(.5,.5)circle(.15) (T1)circle(.15cm and .06cm); } \begin{document} \begin{tikzpicture} \def\x{3} %so luong block \foreach\h in{1,...,\x}{ \drawboxa{1}{1}{\h}{blue!25} } \def\d{.3} \draw(1,-\d) node[scale=1.3]{3}; \draw(.8,\x+1.2*\d) node[scale=1.2, above]{three}; \begin{scope}[xshift=100] \def\x{2} %so luong block \foreach\h in{1,...,\x}{ \drawboxa{1}{1}{\h}{blue!25} } \draw(1,-\d) node[scale=1.3]{2}; \draw(.8,\x+1.2*\d) node[scale=1.2, above]{two}; \end{scope} \begin{scope}[xshift=200] \def\x{5} %so luong block \foreach\h in{1,...,\x}{ \drawboxa{1}{1}{\h}{blue!25} } \draw(1,-\d) node[scale=1.3]{5}; \draw(.8,\x+1.2*\d) node[scale=1.2, above]{five}; \end{scope} \end{tikzpicture} \vspace{1cm} \begin{tikzpicture} \def\x{5} %so luong block %drawbox{x}{z}{y} %x la toa do x %z la toa do lop tinh theo goc xien %y la toa do y \drawboxb{1}{0}{0} \end{tikzpicture} \begin{tikzpicture} \def\x{5} % so luong block xanh \def\v{2} % so luong block vang \def\b{1} % so luong block xanh duong \pgfmathtruncatemacro{\xx}{\x+1} \pgfmathtruncatemacro{\vv}{\x+\v} \pgfmathtruncatemacro{\vvv}{\vv+1} \pgfmathtruncatemacro{\bb}{\vv+\b} \ifnum\x>0 \foreach \h in {1,...,\x}{ \drawboxc{\h}{1}{1}{brown!35} } \fi \ifnum\v>0 \foreach \h in {\xx,...,\vv}{ \drawboxc{\h}{1}{1}{yellow!55} } \fi \ifnum\b>0 \foreach \h in {\vvv,...,\bb}{ \drawboxc{\h}{1}{1}{blue!25} } \fi \end{tikzpicture} \end{document} The code was from user 11232 How to draw stacked cubes of different sizes and colors?

  • Shuffle the puzzle pieces in TikZ interactive puzzle game (based on this TeX.SX project)
    by fsbmat on January 23, 2026 at 12:59 am

    I’ve been working on a variation of the interactive puzzle from this excellent post on TeX StackExchange: 🔗 The TikZ Game Package – a TeX.SX Project ❓Goal I'd like to shuffle the pieces of the puzzle at the start (instead of them being in order) and still keep the interactive movement functionality working (i.e. clicking tiles to move them like a sliding puzzle). ✅ What I have working The puzzle layout builds correctly using TikZ, ocgx2, and media9. I implemented a manual shuffle using a LaTeX macro (\ShuffleIndex) to define the tile order. The initial view of the puzzle shows the image shuffled correctly. ❌ What is broken The JavaScript interaction no longer works after applying the shuffle. Clicking on the tiles gives an error: ReferenceError: onButtonClick is not defined It seems the function is not visible globally or the OCGs are not properly indexed. 💡 What I'm asking Would anyone be able to: Help fix the JavaScript so it works with the shuffled layout? Or alternatively — provide a working example based on the original post, but with the puzzle pieces already shuffled at start? 📎 What I’ve tried Here’s my current version (almost working, but with JS errors): \documentclass[tikz,margin=1mm]{standalone} \usepackage{xsavebox} \usepackage[tikz]{ocgx2} \usepackage{media9} \usepackage{multido} \usepackage{xcolor}\pagecolor{gray} \usepackage{multido} \usepackage{ifluatex} \ifluatex\def\pdfpageattr{\pdfvariable pageattr}\fi \usepackage{tikzmarmots} % imagem base \begin{xlrbox}{Image} \begin{tikzpicture} \useasboundingbox (0,0) rectangle (4.4,4.4); \node at (2.2,2.2) {\tikz\marmot[scale=2.1];}; \end{tikzpicture} \end{xlrbox} % peças do puzzle \multido{\nX=0+1.1,\iI=0+1}{4}{% \multido{\nY=3.3+-1.1,\iJ=0+1}{4}{% \ifnum\numexpr\iI+\iJ\relax>0 \begin{xlrbox}{Image.\the\numexpr\iI+\iJ*4\relax} \begin{tikzpicture} \clip (\nX,\nY) rectangle ++(1.1,1.1); \node[anchor=south west,inner sep=0pt] at (0,0) {\theImage}; \end{tikzpicture} \end{xlrbox} \fi } } \newcommand\MyStatus[2]{\ifnum#1=#2 visible\else invisible\fi} % JavaScript \pdfpageattr{ /AA << /O << /S/JavaScript /JS ( var tile=[], oldTile=[]; for(var i=0;i<4;i++){ tile[i]=[]; oldTile[i]=[]; for(var j=0;j<4;j++){ tile[i][j]=[]; oldTile[i][j]=i+j*4-1; } } var ocg=this.getOCGs(this.pageNum); for(var k in ocg){ var n=ocg[k].name.split('.'); tile[n[0]][n[1]][n[2]-1]=ocg[k]; } var si=0,sj=0; function onButtonClick(i,j){ if(si==i && sj!=j){ for(var y=sj;y!=j;sj<j?y++:y--){ if(y!=sj) tile[i][y][oldTile[i][y]].state=false; oldTile[i][y]=oldTile[i][sj<j?y+1:y-1]; tile[i][y][oldTile[i][y]].state=true; } } else if(sj==j && si!=i){ for(var x=si;x!=i;si<i?x++:x--){ if(x!=si) tile[x][j][oldTile[x][j]].state=false; oldTile[x][j]=oldTile[si<i?x+1:x-1][j]; tile[x][j][oldTile[x][j]].state=true; } } if(si==i||sj==j){ if(oldTile[i][j]>-1) tile[i][j][oldTile[i][j]].state=false; oldTile[i][j]=-1; si=i; sj=j; } } ) >> >> } \def\ShuffleIndex#1{% \csname ShuffleValue#1\endcsname% } \expandafter\def\csname ShuffleValue0\endcsname{5} \expandafter\def\csname ShuffleValue1\endcsname{12} \expandafter\def\csname ShuffleValue2\endcsname{3} \expandafter\def\csname ShuffleValue3\endcsname{14} \expandafter\def\csname ShuffleValue4\endcsname{1} \expandafter\def\csname ShuffleValue5\endcsname{6} \expandafter\def\csname ShuffleValue6\endcsname{11} \expandafter\def\csname ShuffleValue7\endcsname{9} \expandafter\def\csname ShuffleValue8\endcsname{8} \expandafter\def\csname ShuffleValue9\endcsname{2} \expandafter\def\csname ShuffleValue10\endcsname{7} \expandafter\def\csname ShuffleValue11\endcsname{10} \expandafter\def\csname ShuffleValue12\endcsname{15} \expandafter\def\csname ShuffleValue13\endcsname{4} \expandafter\def\csname ShuffleValue14\endcsname{13} \expandafter\def\csname ShuffleValue15\endcsname{0} \begin{document} \newcount\shufcount \shufcount=0 \begin{tikzpicture} \multido{\nX=0+1.1,\iI=0+1}{4}{% \multido{\nY=3.3+-1.1,\iJ=0+1}{4}{% \edef\CellIndex{\the\numexpr\iI+\iJ*4\relax}% \edef\RandIndex{\ShuffleIndex{\CellIndex}}% \multido{\iK=1+1}{15}{% \begin{scope}[ocg={ref=\iI.\iJ.\iK,% status=\MyStatus{\ShuffleIndex{\the\numexpr\iI+\iJ*4\relax}}{\iK}}]% \node[anchor=south west,inner sep=0pt]% at (\nX,\nY) {\xusebox{Image.\iK}};% \end{scope}% }% \draw[line width=0,% postaction={% path picture={% \node[anchor=south west,inner sep=0pt]% at (path picture bounding box.south west)% {\mediabutton[jsaction={onButtonClick(\iI,\iJ);}]{% \tikz \useasboundingbox% (path picture bounding box.south west)% rectangle% (path picture bounding box.north east);}};% }% }]% (\nX,\nY) rectangle ++(1.1,1.1);% }% }% \end{tikzpicture} \end{document} I made the following change to the code: \documentclass[tikz,margin=1mm]{standalone} \usepackage{xsavebox} \usepackage[tikz]{ocgx2} \usepackage{media9} \usepackage{multido} \usepackage{xcolor}\pagecolor{gray} \usepackage{multido} \usepackage{ifluatex} \ifluatex\def\pdfpageattr{\pdfvariable pageattr}\fi \usepackage{tikzmarmots} % imagem base \begin{xlrbox}{Image} \begin{tikzpicture} \useasboundingbox (0,0) rectangle (4.4,4.4); \node at (2.2,2.2) {\tikz\marmot[scale=2.1];}; \end{tikzpicture} \end{xlrbox} % peças do puzzle \multido{\nX=0+1.1,\iI=0+1}{4}{% \multido{\nY=3.3+-1.1,\iJ=0+1}{4}{% \ifnum\numexpr\iI+\iJ\relax>0 \begin{xlrbox}{Image.\the\numexpr\iI+\iJ*4\relax} \begin{tikzpicture} \clip (\nX,\nY) rectangle ++(1.1,1.1); \node[anchor=south west,inner sep=0pt] at (0,0) {\theImage}; \end{tikzpicture} \end{xlrbox} \fi } } \newcommand\MyStatus[2]{\ifnum#1=#2 visible\else invisible\fi} % JavaScript \pdfpageattr{ /AA << /O << /S/JavaScript /JS ( var tile=[], oldTile=[]; for(var i=0;i<4;i++){ tile[i]=[]; oldTile[i]=[]; for(var j=0;j<4;j++){ tile[i][j]=[]; oldTile[i][j]=i+j*4-1; } } var ocg=this.getOCGs(this.pageNum); for(var k in ocg){ var n=ocg[k].name.split('.'); tile[n[0]][n[1]][n[2]-1]=ocg[k]; } var si=0,sj=0; function onButtonClick(i,j){ if(si==i && sj!=j){ for(var y=sj;y!=j;sj<j?y++:y--){ if(y!=sj) tile[i][y][oldTile[i][y]].state=false; oldTile[i][y]=oldTile[i][sj<j?y+1:y-1]; tile[i][y][oldTile[i][y]].state=true; } } else if(sj==j && si!=i){ for(var x=si;x!=i;si<i?x++:x--){ if(x!=si) tile[x][j][oldTile[x][j]].state=false; oldTile[x][j]=oldTile[si<i?x+1:x-1][j]; tile[x][j][oldTile[x][j]].state=true; } } if(si==i||sj==j){ if(oldTile[i][j]>-1) tile[i][j][oldTile[i][j]].state=false; oldTile[i][j]=-1; si=i; sj=j; } } ) >> >> } \def\ShuffleIndex#1{% \csname ShuffleValue#1\endcsname% } \expandafter\def\csname ShuffleValue0\endcsname{5} \expandafter\def\csname ShuffleValue1\endcsname{12} \expandafter\def\csname ShuffleValue2\endcsname{3} \expandafter\def\csname ShuffleValue3\endcsname{14} \expandafter\def\csname ShuffleValue4\endcsname{1} \expandafter\def\csname ShuffleValue5\endcsname{6} \expandafter\def\csname ShuffleValue6\endcsname{11} \expandafter\def\csname ShuffleValue7\endcsname{9} \expandafter\def\csname ShuffleValue8\endcsname{8} \expandafter\def\csname ShuffleValue9\endcsname{2} \expandafter\def\csname ShuffleValue10\endcsname{7} \expandafter\def\csname ShuffleValue11\endcsname{10} \expandafter\def\csname ShuffleValue12\endcsname{15} \expandafter\def\csname ShuffleValue13\endcsname{4} \expandafter\def\csname ShuffleValue14\endcsname{13} \expandafter\def\csname ShuffleValue15\endcsname{0} \begin{document} \newcount\shufcount \shufcount=0 \begin{tikzpicture} \multido{\nX=0+1.1,\iI=0+1}{4}{% \multido{\nY=3.3+-1.1,\iJ=0+1}{4}{% \edef\CellIndex{\the\numexpr\iI+\iJ*4\relax}% \edef\RandIndex{\ShuffleIndex{\CellIndex}}% \multido{\iK=1+1}{15}{% \begin{scope}[ocg={ref=\iI.\iJ.\iK,% status=\MyStatus{\ShuffleIndex{\the\numexpr\iI+\iJ*4\relax}}{\iK}}]% \node[anchor=south west,inner sep=0pt]% at (\nX,\nY) {\xusebox{Image.\iK}};% \end{scope}% }% \draw[line width=0,% postaction={% path picture={% \node[anchor=south west,inner sep=0pt]% at (path picture bounding box.south west)% {\mediabutton[jsaction={onButtonClick(\iI,\iJ);}]{% \tikz \useasboundingbox% (path picture bounding box.south west)% rectangle% (path picture bounding box.north east);}};% }% }]% (\nX,\nY) rectangle ++(1.1,1.1);% }% }% \end{tikzpicture} \end{document} But when compiling and opening Adobe, the game displays errors! The main difference between the two codes is that the first version initializes the puzzle in its natural ordered state, while the second version attempts to introduce a manual shuffle at compilation time. In the first code, each grid cell determines its visible tile using the direct index \the\numexpr\iI+\iJ*4\relax, meaning the logical tile numbering matches the visual position expected by the JavaScript initialization (oldTile[i][j]=i+j*4-1). Thus, the OCG references, the visibility logic (\MyStatus), and the JavaScript tile matrix remain perfectly aligned. In contrast, the second code introduces a \ShuffleIndex mapping that reassigns which tile is visible in each cell by redefining the status condition through a precomputed permutation (ShuffleValue0–ShuffleValue15). Although the OCG naming convention (ref=\iI.\iJ.\iK) remains unchanged, the logical relationship between cell coordinates and tile indices is altered at the TeX level only. As a result, the visual layout becomes shuffled, but the JavaScript still assumes the original positional indexing when constructing oldTile, leading to a mismatch between the PDF layer structure and the JS tile state logic. In short, the first code preserves structural consistency between TeX indexing and JavaScript state management, whereas the second modifies only the initial visibility layer without updating the underlying JS tile model, which explains why interaction breaks after shuffling. I’d appreciate any tips or corrections. If I’m handling the OCG indexing or JavaScript scope wrong, please let me know how to fix it. Thanks in advance!

  • Custom Sidebar Table of Contents in Beamer
    by wrb98 on September 17, 2024 at 2:15 pm

    I'm working with a blank Beamer presentation template and want to recreate a sidebar similar to one shown in the image below. Unlike typical Beamer sidebars that extend to the page's edge, this one is part of a custom frame. I'd like the sidebar to display boxed sections with sharp drop shadows. The current section should be highlighted by a red shadow, while the current subsection should be bolded and appear on a white horizontal strip. Subsections from other sections should remain hidden until the presentation reaches that specific section, at which point they should appear in a dropdown list in the sidebar (e.g. in the image, we're on SO so subsections of SO are shown in the sidebar, but subsections of Section Two and Section Three are not). Note: By 'subsection' I really mean slide titles. How can I implement this effect in LaTeX? Any help would be appreciated. \documentclass[11pt]{beamer} \usepackage{tikz} \usepackage{microtype} \usepackage{xcolor} \usepackage{soul} \usetikzlibrary{calc} \usepackage{ lmodern, babel, amsmath, eurosym } \definecolor{darkpastelgreen}{rgb}{0.01, 0.75, 0.24} \usepackage[default]{sourcesanspro} \usepackage[T1]{fontenc} \setbeamertemplate{navigation symbols}{} \setbeamertemplate{background}{% \begin{tikzpicture}[overlay,remember picture] \fill[sharp corners,fill=darkpastelgreen] ($ (current page.north west) + (0.4cm,-0.4cm) $) rectangle ($ (current page.south east) + (-0.4cm,0.4cm) $); \end{tikzpicture}% \begin{tikzpicture}[overlay,remember picture] \fill[sharp corners,color=white] ($ (current page.north west) + (0.5cm,-0.5cm) $) rectangle ($ (current page.south east) + (-2cm,0.5cm) $); \end{tikzpicture}% } \setbeamersize{text margin left=0.8cm, text margin right=0.85cm} % Reduce side margins \setbeamertemplate{frametitle}{\color{black}\bfseries\insertframetitle \nointerlineskip \bigskip } \addtobeamertemplate{frametitle}{\vspace*{0cm}}{\vspace*{-0.4cm}} \addtolength{\headsep}{0.6cm} \begin{document} \begin{frame}[t]{} \frametitle{A Subsection} Slide content goes here... \end{frame} \end{document}

  • How to draw tangent lines of equal length at three equidistant points on a curved path?
    by myhsia on February 7, 2024 at 2:11 pm

    like the bend triangle below And the MWE is all I can draw. \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture} \draw (0,0) -- (4.5,0) -- (6,2) -- (1.5,2) -- cycle; \draw [xshift=3cm,yshift=1cm] (0,0) ellipse (1.2 and .6); \draw [xshift=3cm,yshift=1cm,->,teal] (0,.6) -- (.6,.6); \draw [xshift=3cm,yshift=1cm,->,teal] (1.2,0) -- (1.9,0); \draw [xshift=3cm,yshift=1cm,->,teal] (0,-.6) -- (.6,-.6); \draw [xshift=3cm,yshift=1cm,->,teal] ({-1.2*cos(30)},{-.6*sin(30)}) --++ (.6,0) node [above] {$v^a$}; \draw [xshift=3cm,yshift=1cm,->,teal] ({-1.2*cos(30)},{.6*sin(30)}) --++ (.6,0); \shade [xshift=3cm,yshift=1cm,ball color=teal] (-1.2,0) circle (.06); \end{tikzpicture} \end{document} Current result:

  • How can I draw a graph of adjacency matrix in Tikz?
    by MAHSA on October 6, 2023 at 12:31 am

    I want to draw this picture, but I can't How can help me?

  • How to move objects in beamer [closed]
    by Solarflares on January 31, 2021 at 7:51 pm

    How can objects be moved with TikZ in beamer - like in this video? (For non german speaking persons: the speaker says that the example at 8:15 is made with beamer and TikZ).

  • How can I create a lightbox/microfilm effect?
    by crmdgn on October 25, 2020 at 12:15 am

    I'm putting together a beamer presentation, and in a moment of madness I had the idea to give it a sort of lightbox/microfilm/transparency effect, sort of like this or this or this. I tend to keep my slides very simple, so this is new territory for me. The only thing I can think to do is some sort of tikz gradient, but that doesn't really get me what I want: \documentclass{standalone} \usepackage{tikz} \usepackage{tcolorbox} \begin{document} \begin{tikzpicture} \fill [black!20] (-0.5,-0.5) rectangle (1.5,1.5); \path [pattern color=black!30] (-0.5,-0.5) rectangle (1.5,1.5); \tcbvignette{fade in=black} \end{tikzpicture} \end{document} That gives you more of a picture frame effect with mitered corners, as here: Is there another approach I can be taking? Is this even within the limits of tikz?

  • How to make a tkz-tab red?
    by Romain on May 4, 2020 at 7:01 am

    I need this tkz-tab \usepackage{tikz,tkz-tab} \begin{document} \begin{tikzpicture} \tkzTabInit{$x$ / 1 , $f\left(x\right)$ / 1}{$-\infty$ , $-\frac{b}{a}$ , $+\infty$} \tkzTabLine{ , \text{Opposé signe } a , z , \text{Signe de } a , } \end{tikzpicture} \end{document} to be red. The whole of it, text, lines, everything. I can't find anything on this forum and I tried to put a [color=red] next to the commands but it only gave me an error. PS: the text in the tab is in French but don't worry 😉

  • How to shift default x=0 for tikzpicture graphs
    by Will Kim on May 31, 2019 at 1:58 pm

    I am trying to produce a probability distribution graph for a discrete random variable. What I want to know is how to shift x=0 to the right so that it is positioned where x=1 is. As you can see, this is not being done for my graph above, using the code below. \documentclass[]{article} \usepackage[margin=0.5in]{geometry} \usepackage{pgfplots} \renewcommand{\thesection}{\arabic{section}} \usepackage{mathtools} \usepackage{cancel} \usepackage{pgfplots} \usepackage{amsmath} \newtheorem{theorem}{THEOREM} \newtheorem{proof}{PROOF} \usepackage{tikz} \usepackage{amssymb} \usetikzlibrary{patterns} \usepackage{fancyhdr} \usepackage{bigints} \usepackage{color} \usepackage{tcolorbox} \usepackage{color,xcolor} \usepackage{booktabs,array} \usepackage{hyperref} \usepackage{graphicx} \usetikzlibrary{arrows} \usepackage{polynom} \usepackage{wallpaper} \usetikzlibrary{shapes.geometric} \usepgfplotslibrary{fillbetween} \newenvironment{tightcenter}{ \setlength\topsep{0pt} \setlength\parskip{0pt} \begin{center}}{\end{center}} \begin{document} \begin{tikzpicture} \begin{axis}[ %axis lines=middle, grid=major, %ticks=none, xmin=0, xmax=4.2, ymin=0, ymax=0.55, clip=false, xtick={0,1,2,3,4}, xticklabels={$0$,$1$,$2$,$3$,$4$}, ytick={0,0.1,0.2,0.3,0.4,0.5}, height=10cm, width=14cm, %axis line style={shorten >=-10pt, shorten <=-10pt}, yticklabel style={ fill=white, %yshift=10pt, }, ylabel=\text{proportion}, xticklabel style={ %xshift=10pt, fill=white }, xlabel=\text{Number of accidents per week}, ylabel near ticks, xlabel near ticks %ylabel style={rotate=-90} ] %\node[below] at (axis cs:-1.5,0) {$O$}; %\draw[fill=black](axis cs:30,35) circle (3pt); %\draw[fill=black](axis cs:15,20) circle (3pt); %\draw[fill=black](axis cs:25,20) circle (3pt); %\draw[fill=black](axis cs:12,10) circle (3pt); %\draw[fill=black](axis cs:25,22) circle (3pt); %\draw[fill=black](axis cs:32,40) circle (3pt); %\draw[fill=black](axis cs:50,30) circle (3pt); %\draw[fill=black](axis cs:45,40) circle (3pt); %\draw[fill=black](axis cs:60,50) circle (3pt); %\draw[fill=black](axis cs:20,15) circle (3pt); %\draw[fill=black](axis cs:15,10) circle (3pt); %\draw[fill=black](axis cs:19,20) circle (3pt); %\draw[fill=black](axis cs:25,20) circle (3pt); %\draw[fill=black](axis cs:45,40) circle (3pt); %\draw[fill=black](axis cs:50,45) circle (3pt); % \draw[thick,fill=gray,opacity=0.5] (axis cs: 0-0.2,0) rectangle (axis cs: 0+0.2,0.45); \draw[thick,fill=gray,opacity=0.5] (axis cs: 1-0.2,0) rectangle (axis cs: 1+0.2,0.3); \draw[thick,fill=gray,opacity=0.5] (axis cs: 2-0.2,0) rectangle (axis cs: 2+0.2,0.15); \draw[thick,fill=gray,opacity=0.5] (axis cs: 3-0.2,0) rectangle (axis cs: 3+0.2,0.1); \end{axis} \end{tikzpicture} \end{document} The following graph is what I am trying to replicate: Thank you in advance.

  • Seven segment display with TikZ
    by current_user on January 6, 2019 at 5:36 pm

    Consider the following MWE: \documentclass[border=5pt,tikz]{standalone} \usepackage{ifthen} \newcommand{\binary}[3]{ \pgfmathsetmacro\number{int(#1*2^0+#2*2^1+#3*2^2)} } \newcommand{\sieben}[1]{ \draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5); \draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5); \draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5); \draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0); \draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0); \draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0); \ifthenelse{\equal{#1}{0}}{ \draw[red,line width=3pt] (0,0) --+ (0,.5); \draw[red,line width=3pt] (0,.6) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); \draw[red,line width=3pt] (.1,-.05) --+ (.5,0); }{} \ifthenelse{\equal{#1}{1}}{ \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); }{} \ifthenelse{\equal{#1}{2}}{ \draw[red,line width=3pt] (.1,1.18) --+ (.5,0);; \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); \draw[red,line width=3pt] (.1,.55) --+ (.5,0); \draw[red,line width=3pt] (0,0) --+ (0,.5); \draw[red,line width=3pt] (.1,-.05) --+ (.5,0); }{} \ifthenelse{\equal{#1}{3}}{ \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); \draw[red,line width=3pt] (.1,-.05) --+ (.5,0); \draw[red,line width=3pt] (.1,.55) --+ (.5,0); }{} \ifthenelse{\equal{#1}{4}}{ \draw[red,line width=3pt] (0,.6) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); \draw[red,line width=3pt] (.1,.55) --+ (.5,0); }{} \ifthenelse{\equal{#1}{5}}{ \draw[red,line width=3pt] (0,.6) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); \draw[red,line width=3pt] (.1,.55) --+ (.5,0); \draw[red,line width=3pt] (.1,-.05) --+ (.5,0); }{} \ifthenelse{\equal{#1}{6}}{ \draw[red,line width=3pt] (0,0) --+ (0,.5); \draw[red,line width=3pt] (0,.6) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); \draw[red,line width=3pt] (.1,-.05) --+ (.5,0); \draw[red,line width=3pt] (.1,.55) --+ (.5,0); }{} \ifthenelse{\equal{#1}{7}}{ \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); }{} \ifthenelse{\equal{#1}{8}}{ \draw[red,line width=3pt] (0,0) --+ (0,.5); \draw[red,line width=3pt] (0,.6) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); \draw[red,line width=3pt] (.1,-.05) --+ (.5,0); \draw[red,line width=3pt] (.1,.55) --+ (.5,0); }{} \ifthenelse{\equal{#1}{9}}{ \draw[red,line width=3pt] (0,.6) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); \draw[red,line width=3pt] (.1,-.05) --+ (.5,0); \draw[red,line width=3pt] (.1,.55) --+ (.5,0); }{} \ifthenelse{\equal{#1}{a}}{ \draw[red,line width=3pt] (0,0) --+ (0,.5); \draw[red,line width=3pt] (0,.6) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5); \draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5); \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); \draw[red,line width=3pt] (.1,.55) --+ (.5,0); }{} % \ifnum#1>9 % \draw[red,line width=3pt] (0,0) --+ (0,.5); % \draw[red,line width=3pt] (0,.6) --+ (0,.5); % \draw[red,line width=3pt] (.1,1.18) --+ (.5,0); % \draw[red,line width=3pt] (.1,-.05) --+ (.5,0); % \draw[red,line width=3pt] (.1,.55) --+ (.5,0); % \fi } \begin{document} \begin{tikzpicture}[xslant=0] \sieben{a} \begin{scope}[xshift=1.5cm] \binary{1}{1}{1} % seven in dual system \sieben{\number} \end{scope} \end{tikzpicture} \end{document} Here is the output: My problem is: When I uncomment the commented part in the definition of the command (\ifnum#1>9 …) and I type as an argument the letter "a", I get an error. But when I comment this part, I don't. My question is: How can I fix this error?

  • Vertical strikethrough in table is too long
    by Labbiqa on March 7, 2015 at 5:45 pm

    So I just started using LateX yesterday and ran into a problem. I'm making a table where a number is circled and the whole row is crossed out. I found different codes on the internet and tried applying them to the table. Here's the code: \documentclass[12pt,a4paper]{article} \usepackage{amsmath,amssymb,amsthm, amsfonts} \usepackage{tikz-inet} \usepackage{graphicx} \usetikzlibrary{matrix} \usepackage{tikz} Command to make circle: \usetikzlibrary{fit,shapes.geometric} \newcounter{nodemarkers} \newcommand\circletext[1]{% \tikz[overlay,remember picture] \node (marker-\arabic{nodemarkers}-a) at (0,1.5ex) {};% #1% \tikz[overlay,remember picture] \node (marker-\arabic{nodemarkers}-b) at (0,0){};% \tikz[overlay,remember picture,inner sep=2pt] \node[draw,ellipse,fit=(marker-\arabic{nodemarkers}-a.center) (marker-\arabic{nodemarkers}-b.center)] {};% \stepcounter{nodemarkers}% } Command to make lines in the table: \newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {$#2$};} \newcommand{\DrawVLine}[3][]{% \begin{tikzpicture}[overlay,remember picture] \draw[shorten <=0.3ex, #1] (#2.north) -- (#3.south); \end{tikzpicture} } \newcommand{\DrawHLine}[3][]{% \begin{tikzpicture}[overlay,remember picture] \draw[shorten <=0.2em, #1] (#2.west) -- (#3.east); \end{tikzpicture} } The table: \begin{document} \begin{center} \renewcommand{\arraystretch}{1.3} \begin{tabular}{c|cccc} \multicolumn {1}{c|}{} & 60 & 110 & 80 & 110 \\ \hline 80 & \tikzmark{topA}{3} & \tikzmark{topB}{10} & \tikzmark{topC}{20} & \tikzmark{topD}{ \circletext{0} } \\ 20 & 2 & 1 & 3 & \tikzmark{rightB}{0} \\ 50 & 2,5 & 3,5 & 4 & \tikzmark{rightC}{0} \\ 210 & 4 & 5 & 9 & \tikzmark{rightD}{0} \\ \DrawVLine[blue, thick, opacity=0.8]{topD}{rightD} \end{tabular} \end{center} \end{document} As you can see the vertical line is too long. Can anyone tell me where the code went wrong? If I try to remove \DrawVLine[blue, thick, opacity=0.8]{topD}{rightD} it looks fine though.

  • Adding vertical hierarchy lines to a category column of a table
    by badroit on August 8, 2014 at 8:15 pm

    I often need to represent hierarchies within tables but I've yet to find an elegant way to do this. Oftentimes I do a variation on the following theme, with nested whitespace in the category column: \documentclass{article} \usepackage{booktabs} \newcommand{\lvl}{~~~} \begin{document} \begin{tabular}{lr} \toprule \textbf{Category} & \textbf{\%}\\ \midrule Animal & 100 \\ \lvl Human & 50 \\ \lvl\lvl Man & 20 \\ \lvl\lvl Woman & 30 \\ \lvl Fox & 30 \\ \lvl\lvl Vixen & 16 \\ \lvl\lvl Dog & 14 \\ \lvl Chicken & 20 \\ \lvl\lvl Cock & 8 \\ \lvl\lvl Hen & 12 \\ \bottomrule \end{tabular} \end{document} I might mix that up with midrules between categories and different fonts for different levels and so on. But the result can sometimes be very "busy", especially if there's a bunch of levels. Instead, I was playing around with the idea of adding lines to more elegantly represent the hierarchy, sketched as follows in red (a similar effect in the same spirit would also suffice): But I'm not sure how to realise this in LaTeX in an elegant way. I'm guessing I could somehow decorate a table with TikZ but I'd only know how to specify manual points (e.g., I'm not sure how to anchor rows in a table). Thus I'm looking for any suggestions of elegant solutions to achieve the above effect. (An ideal answer would avoid explicit coordinates/distances and would be "highly reusable".)

  • LaTeX Beamer, TikZ and overlays — page numbering issue
    by georgmierau on March 20, 2014 at 10:09 am

    I'm using \onslide<…-> for overlays in TikZ: \documentclass{beamer} \usepackage{tikz} \setbeamertemplate{footline}{\insertpagenumber{}} \begin{document} \begin{frame} \begin{tikzpicture} \draw node[] at (0, 0) {$s_0$}; \onslide<2->{ \draw node[] at (1, 1) {$s_1$}; } \onslide<3->{ \draw node[] at (2, 2) {$s_2$}; } \end{tikzpicture} \end{frame} \end{document} …and there are no more annoying additional bullets in the headline for every single overlay, but the page number is still increasing (so I'm getting only one bullet but 1, 2, 3 as page numbers). Is there any solution this problem?

  • How to draw slope fields with all the possible solution curves in latex
    by MaoYiyi on October 16, 2013 at 3:17 am

    Sorry, I have no code to submit, mostly because I have no idea how to do this. I want to type up my homework (I can do the homework by hand) and I am looking for a simple method that I can use repetitively on different equations; without having to code each equation; to make/produce/draw the slope field of that equation. Currently, I have typed up the rest of my homework with latex, but have no good example from the internet to follow. I want to put the slope fields for both $\frac{\mathrm{d}y}{\mathrm{d}x}=2x$ and $\frac{\mathrm{d}y}{\mathrm{d}x}=x\sqrt{x}$ into my homework. My system is Fedora 19. Any suggestions? ps. sorry if this is a poor quality question. I just used the suggested tags.

  • How to insert a linebreak in a TikZ matrix node?
    by Tim N on May 6, 2013 at 6:34 am

    How can I get a linebreak inside a matrix node? The following gives the error: Package tikz Error: Giving up on this path. Did you forget a semicolon?. unless I remove the linebreak. \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{chains} \usetikzlibrary{matrix} \begin{document} \begin{tikzpicture} \matrix (m) [ matrix of nodes ] { {some text} & {this node \\ does not work} \\ {other text} & {more text} \\ }; \end{tikzpicture} \end{document}

  • Create a math matrix in TikZ partition lines
    by aagaard on August 26, 2011 at 3:51 pm

    I want to draw a math matrix in TikZ, where I can draw helping partition lines. So far I found it pretty simple to just draw a matrix with brackets. \begin{tikzpicture} \matrix [matrix of math nodes,left delimiter={[},right delimiter={]}] { 1 & 2 & 1 & 0 & 0 & 10 \\ 3 & 2 & 0 & 1 & 0 & 20 \\ -2 & -10 & 0 & 0 & 1 & 0 \\ }; \end{tikzpicture} However, I would like to partition the matrix with a vertical line between columns 5 and 6, and a horizontal line between rows 2 and 3. Furthermore it could nice to have "identification variables" outside the brackets (top).