• Creating Circular Domains with TikZ
    by Assuério Cavalcante on February 10, 2026 at 3:45 pm

    First, apologies if this question has been asked before. I'm trying to create an image of a particular circular domain, but my limited TikZ knowledge has made this quite challenging. I've searched for similar examples online without success. Any guidance would be greatly appreciated!

  • MetaPost, TikZ and their 3D libraries
    by Sebastiano on February 10, 2026 at 11:55 am

    I am referring to this Italian lecture notes by Prof. R. Tauraso, edited by a student/lecturer Massimiliano Pompegnani (link https://moodle2.units.it/pluginfile.php/767967/mod_resource/content/1/intdoppi.pdf) My question concerns which specific libraries are needed to draw in 3D (I’m not very familiar with 3D) what to me seems drawn in MetaPost and peraphs, for the their complexity, with IPE drawing https://ipe.otfried.org/ (?), WinFIG (?). From the axes arrows it appears to be MetaPost and also the fills. ecc. I’m not asking for any code but want to be informed. There are many 3D libraries for TikZ but I have never previously been interested in 3D. Are there any similar libraries that TikZ can use to reproduce Metapost drawings?

  • TikZ curved arrow bisecting text - how to increase arc height to clear obstacle?
    by Oregon Math Tutor on February 9, 2026 at 8:19 pm

    I'm annotating a fraction with TikZ arrows pointing to specific parts. The blue arrow works fine, but the red curved arrow is bisecting the "3" in the denominator instead of arcing over it. Current behavior: The red arrow cuts straight through the middle of "3" Desired behavior: The red arrow should arc upward and over the "3" with clear space. I initially tried adjusting the out angle from 160° to 120° to make it launch upward, but this still results in the arrow bisecting the number. How do I increase the arc height to make the curve clear the "3" completely as shown in the 2nd image? Note: I'm still learning TikZ best practices. If you spot any obvious improvements to the code structure, please mention them. MWE \usepackage{mathtools} \usetikzlibrary{calc, arrows.meta} \definecolor{textBlue}{RGB}{50, 50, 255} \definecolor{deepRed}{RGB}{200, 40, 40} \begin{document} \begin{tikzpicture} % Math fraction \node (fraction) at (0,0) { \scalebox{1.8}{% $\displaystyle \frac{2x^3 - 5x^2 - x + 3}{x + 3}$ } }; % Blue annotation (works fine) \node[ellipse, draw=textBlue, dashed, minimum width=0.3cm, minimum height=0.6cm, xshift=-0.4cm, yshift=0.4cm] (blueCircle) at ($(fraction.south) + (-0.65, 0.28)$) {}; \node[draw=textBlue, text=textBlue, align=center, anchor=north] (blueLabel) at ($(blueCircle.south) + (0, -0.6)$) {coefficient\\must be 1}; \draw[textBlue, ->, >=latex] (blueLabel.north) -- (blueCircle.south); % Red annotation (PROBLEM: arrow bisects the "3") \node[circle, draw=deepRed, dashed, minimum size=0.2cm, xshift=-0.2cm, yshift=0.3cm] (redCircle) at ($(fraction.south) + (-0.2, 0.55)$) {}; \node[draw=deepRed, text=deepRed, align=left, anchor=west] (redLabel) at ($(fraction.south) + (0.8, 0.3)$) {exponent\\must be 1}; % This arrow bisects "3" - how to make it arc higher? \draw[deepRed, ->, >=latex] (redLabel.west) to[out=120, in=0] (redCircle.east); \end{tikzpicture} \end{document}``` [1]: https://i.sstatic.net/zirlpD5n.png [2]: https://i.sstatic.net/BOIovYSz.png

  • Watermark misplacement with standalone class
    by Erwann on February 9, 2026 at 3:51 pm

    When using the standalone document class with a shipout hook to add a watermark, it fails to display. Output using article class is OK. \documentclass{standalone} %\documentclass{article} \usepackage{tikz} \AddToHook{shipout/background}{ \begin{tikzpicture}[remember picture, overlay, text=red] \node[ rotate=45, scale=1, opacity=0.5, anchor=center, font=\large] at (current page.center) {WATERMARK}; \end{tikzpicture} } \begin{document} % Uncomment for class article %\vspace*{\fill} %\begin{center} \begin{tikzpicture} \draw[thick] (0,0) rectangle (5,3); \node at (2.5,1.5) {Content}; \end{tikzpicture} %\end{center} % article %\vspace{\fill} % article \end{document} P.S. This requires two compilation passes.

  • pgfplots: align legend entries at a groupplot
    by cis on February 9, 2026 at 2:09 pm

    I have a groupplot where I want to use the legend as the title in the \nextgroupplots. And then I have a "Supertitel" that I would like to put in place of the first groupplot. How do I set it such that the text, like the small box, is aligned to the top edge? \documentclass[margin=5pt, varwidth]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{groupplots} \usetikzlibrary{patterns} \begin{document} \begin{tikzpicture}[font=\footnotesize, mypattern/.style={% postaction={pattern=north east lines}, },% ] \begin{groupplot}[ group style={% group size=2 by 3, vertical sep=15mm, },% height=30mm,width=55mm, group/every plot/.style={%% ybar=0pt, bar width=1, bar shift=0pt, xmin=-0.5,% to see the bar at x=0 correctly ymin=0, xtick=data, },%% end of group/every plot/.style %% every axis plot/.style={ fill=lightgray, area legend,% legend as title 1/2 }, legend style={% legend as title 2/2 at={(0,1)}, yshift=6pt, anchor=south west, draw=none, fill=none, inner sep=0pt, cells={anchor=north, align=left},% PROBLEM HERE ..... },% ] \nextgroupplot[hide axis=true, title={Supertitle}, title style={at={(0.5,0.5)}, anchor=center, yshift=-6pt,% kill pgfplots's default draw=none, font=\bfseries\Large} ] \addplot[draw=none, fill=none]{x};% to avoid warning; don't know how to make this else \nextgroupplot[] \addplot[samples at={0,...,8}, forget plot]{x}; \addplot[mypattern, samples at={3,...,6}]{x}; \addlegendentry{plot 0: \\ plot good, \\ legend bad :(} \end{groupplot} \end{tikzpicture} \end{document}

  • Using xint in pgfplots (example: binomial distribution)
    by cis on February 9, 2026 at 9:26 am

    If I have a function with xint, say % \bdceval{<n>}{<p>}{<k>} \xintNewFloatExpr{\bdeval}[3]{% %B(n,p,k) = binomial(n,k)*p^k*(1-p)^(n-k) % formula binomial(#1,#3)*#2^#3*(1-#2)^(#1-#3)} this works well in text (e.g. \bdeval{13}{0.4}{5}); but how can I use that in pgfplots? In the following MWE I have drawn an example using pgfplots; the same curve should result with xint. \documentclass[margin=5pt, varwidth]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{xintexpr} %\usepackage{xinttools}% needed? % \bdceval{<n>}{<p>}{<k>} \xintNewFloatExpr{\bdeval}[3]{% %B(n,p,k) = binomial(n,k)*p^k*(1-p)^(n-k) % formula binomial(#1,#3)*#2^#3*(1-#2)^(#1-#3)} % \bd[<digits, default: 4>]{<n>}{<p>}{<k>} \NewExpandableDocumentCommand{\bd}{O{4} mmm}{% %\xinteval{round(#2+#3+#4,2)}% for tests \xintRound{#1}{\bdeval{#2}{#3}{#4}}% rounded bd-values } \begin{document} \section{xint in Text (works)} $B(13,0.4,5) =\bdeval{13}{0.4}{5} \approx \bd{13}{0.4}{5}$ \par $B(1000,0.4,50) =\bdeval{1000}{0.4}{50} \approx \bd{1000}{0.4}{50}$ \section{xint in pgfplots (works not)} \begin{tikzpicture}[font=\footnotesize, declare function={ binom(\n,\p,\k)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);% works %xbinom(\n,\p,\k)=\bdeval{\n}{\p}{\k};% works not } ] \begin{axis}[ title={\texttt{xint} in pgfplots?}, title style={fill=blue!25}, xlabel={$k$}, ylabel={$P(X=k)$}, yticklabel style={ /pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=2 }, xtick=data, variable=\k, only marks, ] \addplot+[samples at={0,...,13}] {binom(13, 0.4, k)}; % DOES NOT WORK %\addplot [samples at={0,...,13}] {\bd{13}{0.4}{\k} }; \end{axis} \end{tikzpicture} \end{document}

  • How can I horizontally align two math labels by their baseline in TikZ?
    by Jasper on February 9, 2026 at 2:27 am

    How can I horizontally align two math labels by their baseline in TikZ? \documentclass[tikz,border=1cm]{standalone} \begin{document} \begin{tikzpicture} \node[below] at (0,0) {\(\frac{1}{1}\)}; \node[below] at (1,0) {\(1\)}; \end{tikzpicture} \end{document}

  • Standard practices in label decluttering: overcoming overlapping label lines
    by Jasper on February 8, 2026 at 11:59 pm

    I have a situation where I want to lable the sample points of a line segment, and also label the smaller line segments connecting those sample points. My labels are really cluttered right now. How can I make this more proper? \documentclass[tikz,border=1cm]{standalone} \begin{document} \begin{tikzpicture} \draw[thick,->] (-1,0) -- (5,0) node[below left] {\(x\)}; \fill (0.5,0) circle[radius = 3pt] node[above] {point}; \fill[gray] (0.5,0) circle[radius = 1.5pt]; \draw[] (0.5,0) -- (0.5,-2) -- (5,-2) node[right] {individual sample point}; \draw[line width = 6pt] (2,0) -- (3.5,0) node[above,pos=0.5]{line segment}; \foreach[count = \c from 1] \x in {2,2.5,...,3.5} { \fill[gray] (\x,0) circle[radius = 1.5pt]; \draw[] (\x,0) -- (4,-1); \ifnum\c=4\else\draw[thick,gray] (\x,0) -- ++(0.5,0);\fi } \draw[](4,-1) -- (5,-1) node[right] {multiple sample points}; \foreach[count = \c from 1] \x in {2.25,2.75,...,3.25} { \draw[] (\x,0) -- (4,-1.5); } \draw[](4,-1.5) -- (5,-1.5) node[right] {one or more line segments}; \end{tikzpicture} \end{document}

  • pgfplots: axis-enlargement at a ybar plot (example: binomial distribution)
    by cis on February 8, 2026 at 4:34 pm

    I wanted to adapt this nice solution for my purposes. • I want to extend the x- and y-axes a bit. But, when I set enlarge y limits={upper, abs=0.125} it creates a strange gap (ymin=0 is no longer respected, and restrict y to domain=0:1 seems to have no effect). • Secondly, what's the best way to configure it so that bars with very small y-values ​​are also visible here? • Unfortunately, I saw this too late: I would also like to eliminate this x-gap between the first bar and the y-axis! \documentclass[margin=5pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture}[font=\footnotesize, declare function={ binom(\n,\p,\k)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k); } ] \begin{axis}[%y=8mm, no effect ymin=0, xmin=0, axis lines=left, axis line style={-latex}, xlabel={$k$}, ylabel={$P(X=k)$}, x label style={at={(axis description cs:1,0)}, anchor=south east, inner xsep=0pt }, y label style={at={(axis description cs:0,1)}, rotate = -90, anchor=north west, inner ysep=0pt, }, yticklabel style={ /pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=2 }, ybar=0pt, bar width=1, bar shift=0pt, samples at={0,...,13}, variable=\k, enlarge x limits={upper, abs=0.785}, enlarge y limits={upper, abs=0.125}, %restrict y to domain=0:1,% no effect.... ] \addplot [fill=gray!25] {binom(13, 0.4, k)}; %\addplot [fill=orange, samples at={0,...,4}] {binom(12,0.4,k)}; %\addplot [fill=cyan, samples at={7}] {binom(12,0.4,k)}; \end{axis} \end{tikzpicture} \end{document}

  • How can I draw a coloured factorization diagram?
    by Bayaraa Surenjav on February 8, 2026 at 4:11 pm

    My code is: \documentclass[tikz,border=10pt]{standalone} \usepackage[utf8]{inputenc} \usepackage[mongolian]{babel} \usepackage{amsmath} \usetikzlibrary{calc, positioning, arrows.meta, backgrounds, shapes.geometric} \begin{document} \begin{tikzpicture}[ num node/.style={ font=\Large\bfseries\rmfamily, % Serif font, Bold anchor=east, inner sep=3pt, minimum height=0.65cm }, div node/.style={ font=\Large\rmfamily, anchor=east, inner sep=3pt }, arrow style/.style={ ->, >=latex, draw=cyan!80!blue, line width=0.8pt }, label text/.style={ text=cyan!80!blue, font=\itshape, align=right }, % Үйлдлийн тэмдэг (div 2) op label/.style={ text=cyan!80!blue, font=\large, anchor=west, xshift=2pt } ] \def\rowh{0.9} \node[div node] (d1) at (0,0) {2)}; \node[num node] (n1) at (1.8,0) {120}; \draw[thick] (d1.south east) -- (n1.south east); \node[div node] (d2) at (0,-\rowh) {2)}; \node[num node] (n2) at (1.8,-\rowh) {60}; \draw[thick] (d2.south east) -- (n2.south east); \node[div node] (d3) at (0,-2*\rowh) {2)}; \node[fill=cyan!25, inner sep=2pt, minimum height=0.6cm, minimum width=0.8cm, anchor=east] at (1.85,-2*\rowh) {}; \node[num node, text=magenta] (n3) at (1.8,-2*\rowh) {30}; \draw[thick] (d3.south east) -- (n3.south east); \node[div node] (d4) at (0,-3*\rowh) {3)}; \node[num node] (n4) at (1.8,-3*\rowh) {15}; \draw[thick] (d4.south east) -- (n4.south east); \node[num node] (n5) at (1.8,-4*\rowh) {5}; \begin{scope}[on background layer] % Зүүн талын босоо багана (Хуваагчдыг хамарсан) \fill[cyan!15] (-0.8, 0.4) rectangle (0.2, -4.5*\rowh); \fill[cyan!15] (-0.8, -3.65*\rowh) rectangle (2.2, -4.5*\rowh); \end{scope} \def\arm{0.5} \draw[arrow style] (n1.east) -- ++(\arm,0) |- node[pos=0.25, op label] {$\div 2$} (n2.east); \draw[arrow style] (n2.east) -- ++(\arm,0) |- node[pos=0.25, op label] {$\div 2$} (n3.east); \draw[arrow style] (n3.east) -- ++(\arm,0) |- node[pos=0.25, op label] {$\div 2$} (n4.east); \draw[arrow style] (n4.east) -- ++(\arm,0) |- node[pos=0.25, op label] {$\div 3$} (n5.east); \node[label text] (txt1) at (-3.5, 0) {анхны тоогоор хуваах}; \draw[arrow style] (txt1) -- (d1.west); \node[label text] (txt2) at (-4, -4*\rowh) {анхны тоо гартал үргэлжлүүлнэ}; \draw[arrow style] (txt2) -- (n5.west); \end{tikzpicture} \end{document} Current: Intended:

  • tikz euclides draw circle hung
    by Vuvi Numa on February 8, 2026 at 1:49 pm

    The MWE below freezes on the commented out line, until it is killed with Ctrl-C. This is a part of an old manuscript that was published, several years in the past, so at some point it did work. \documentclass{standalone} \usepackage{tikz} \usepackage{tkz-euclide} \begin{document} \begin{tikzpicture} \draw(-1,-1) rectangle(1,1); \tkzDefPoint(3,-1){A}; \tkzDefPoint(6,-1){B}; \tkzDefPoint(3,1){C}; %\tkzDrawCircle[in](A,B,C); \end{tikzpicture} \end{document} The last few lines of pdflatex output are: (/usr/share/texlive/texmf-dist/tex/latex/tkz-euclide/tkz-draw-eu-protractor.tex 2023/02/03 5.02c tkz-obj-eu-protractor.tex )) No file test.aux. (/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] ) (/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty (/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)) Missing character: There is no ; in font nullfont! Missing character: There is no ; in font nullfont! Missing character: There is no ; in font nullfont! ^C! Interruption. \pgfkeys@parse ...uturelet \pgfkeys@possiblerelax \pgfkeys@parse@main l.12 \tkzDrawCircle[in](A,B,C) ; How can I fix the freeze and allow the arch to be drawn?

  • Best way to set pgf-grouplots and others inside a table
    by cis on February 8, 2026 at 1:21 pm

    I have a table, it looks like this: But I'm having a few problems. What's the best way to set the keys? The table contains a 2×2 groupplot and a formula next to another plot (this plot can be larger than the others). I want to use the entire width of the yellow box! What's the best way to set this up? (In the MWE, I only set it visually.) The formula should be vertically centered or top-centered, whichever is easier to set or looks better. The number of columns with the numbers (1111, 2222,...) is variable, but I don't think that matters because: The entire table should have the page width. Note: The reason I put everything in newcommands is that the original table is actually a pgfplotstable - I'm simulating it here. \documentclass[paper=a5]{scrartcl} \usepackage[margin=14mm, showframe=true]{geometry} \usepackage{amsmath} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{groupplots} \usepackage{colortbl}% \rowcolor, \cellcolor \usepackage{diagbox}% \diagbox \usepackage{hhline}% \hhline{~|-------|} and so on \newcommand\Mydiagrams{ \begin{tikzpicture}[] \begin{groupplot}[group style={group size=2 by 2}, height=30mm,width=49mm, no marks, title style={inner sep=0pt} ] \nextgroupplot[title=plot 1] \addplot{x}; \nextgroupplot[title=plot 2] \addplot{x^2}; \nextgroupplot[title=plot 3] \addplot{x^3}; \nextgroupplot[title=plot 4] \addplot{x^4}; \end{groupplot} \end{tikzpicture}} \newcommand\Myheaddiagram{% \begin{tikzpicture}[] \begin{axis}[ height=30mm,width=49mm, no marks, title style={inner sep=0pt}, title=plot 0, ] \addplot{sin(deg(x))+2}; \end{axis} \end{tikzpicture}} \newcommand\Headformula{% $F(a,b,c) =\displaystyle\sum\limits_{v=0}^k \binom{a}{b} a^v (b+c)^{n-v}$ }% \newcommand\Myhead{% \begin{tabular}[t]{| @{}l@{} | @{}c@{} |}% tabular for linebreaks \arrayrulecolor{blue} \Headformula & \Myheaddiagram \\ \multicolumn{2}{|c|}{\Mydiagrams} \end{tabular} }% \begin{document} \section{Diagramms} \setlength\arrayrulewidth{2pt}% test: correctness of the rules \footnotesize\sffamily% wanted \noindent\begin{tabular}{c | c | *{7}{c} |c|} \hhline{~| *{8}{-} |} & \multicolumn{8}{l|}{\cellcolor{yellow}\Myhead} & \multicolumn{1}{c}{c'} \\ \hhline{-| *{8}{-} -|} \rowcolor{pink} aaa & bbb & 0.1111 & .2222 & .3333 & .4444 & .5555 & .6666 & .7777 & ccc \\ aaa & bbb & 0.1111 & .2222 & .3333 & .4444 & .5555 & .6666 & .7777 & ccc \\ aaa & bbb & 0.1111 & .2222 & .3333 & .4444 & .5555 & .6666 & .7777 & ccc \\ \hline aaa & \diagbox{p}{k} & 0.1111 & .2222 & .3333 & .4444 & .5555 & .6666 & .7777 & \diagbox{p}{k} \\ \end{tabular} \end{document}

  • Displaying equations involving TikZ graphics on a WordPress site with MathJax [closed]
    by abcdf on February 7, 2026 at 12:09 am

    I am writing a website using WordPress with MathJax. In my LaTeX documents, I use TikZ to construct equations that include graphics embedded in the math (for example, superscripts or subscripts connected by lines drawn with TikZ). I would like to display equations of this kind on my website as well. An example of the desired output is shown in the image below. While this works fine in LaTeX, I do not know how to achieve a similar result on a website using MathJax (or related tools such as tikzjax). Is this possible in principle? If so, what would be the recommended approach? Any help or pointers would be greatly appreciated. The following code produces the equation shown in the image in a LaTeX environment using TikZ. \documentclass[a4paper,15pt,riqno]{bxjsreport}%{bxjsarticle} \usepackage[ipa]{zxjafont} \usepackage{tikz-cd} \usetikzlibrary{calc} \usepackage{amsmath} \usetikzlibrary{tikzmark} \begin{document} \begin{align} a^{\tikzmarknode{X}{x}} +b^{\tikzmarknode{Y}{y}} =c^{\tikzmarknode{Z}{z}} \end{align} \tikz[remember picture,overlay]{ \coordinate (Xp) at ($(X.north)+(0,0.3ex)$); \coordinate (Yp) at ($(Y.north)+(0,0.3ex)$); \coordinate (Zp) at ($(Z.north)+(0,0.3ex)$); \path let \p1 = (Xp), \p2 = (Yp), \p3 = (Zp) in coordinate (TopX) at (\x1,{max(\y1,\y2,\y3)+2ex}) coordinate (TopY) at (\x2,{max(\y1,\y2,\y3)+2ex}) coordinate (TopZ) at (\x3,{max(\y1,\y2,\y3)+2ex}); \draw (Xp) -- (TopX); \draw (Yp) -- (TopY); \draw (Zp) -- (TopZ); \draw (TopX) -- (TopY) -- (TopZ); } \begin{align} d_{\tikzmarknode{X}{p}} +e_{\tikzmarknode{Y}{q}} =f_{\tikzmarknode{Z}{r}} \end{align} \tikz[remember picture,overlay]{ \coordinate (Xp) at ($(X.south)+(0,-0.3ex)$); \coordinate (Yp) at ($(Y.south)+(0,-0.3ex)$); \coordinate (Zp) at ($(Z.south)+(0,-0.3ex)$); \path let \p1 = (Xp), \p2 = (Yp), \p3 = (Zp) in coordinate (BottomX) at (\x1,{min(\y1,\y2,\y3)-2ex}) coordinate (BottomY) at (\x2,{min(\y1,\y2,\y3)-2ex}) coordinate (BottomZ) at (\x3,{min(\y1,\y2,\y3)-2ex}); \draw (Xp) -- (BottomX); \draw (Yp) -- (BottomY); \draw (Zp) -- (BottomZ); \draw (BottomX) -- (BottomY) -- (BottomZ); } \end{document}

  • Drawing diagrams in latex [duplicate]
    by Noah on February 6, 2026 at 4:43 pm

    I’m relatively new at diagram drawing in latex. How would I go about drawing an upper half sphere with an elliptic curve plotted along it (to resemble the real projective plane)? I want it to look something like this where you have the upper-half sphere drawn and shaded in a solid light grey, and the intersection of the equation X^3-3XZ^2+3Z^3-Y^2Z=0 with the upper-half sphere, the point (0,1,0) annotated with infinity, and the viewing angle rotated as in the image (and possibly the curve in another colour). I really don’t like the usual 3D look but prefer the way the following attached images look. I’d greatly appreciate your help!

  • Finding and displaying the intersection points of two surfaces
    by SH.Madadpour on February 6, 2026 at 10:23 am

    How can I display the intersection of the following two surfaces in LaTeX? I have used the following codes as a default but I am not getting acceptable output. Is it possible to create a form to find its intersection points in LaTeX? Thanks a lot. \documentclass[border=3.14mm]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.16} \begin{document} \begin{tikzpicture} \begin{axis}[domain=0.01:30,xlabel=$x$] \addplot3[surf,domain={0:1},color=green]{x^3+y^3}; \addplot3[surf,domain={0:1},color=red]{(x*(1-y^2)^(.5)+y*(1-x^2)^(.5))^3}; \end{axis} \end{tikzpicture} \end{document}

  • tikz / xint: Read out (and calc with) fractions from list (or array) with xint or pgfmath
    by cis on February 6, 2026 at 8:45 am

    How can I read out numbers from a list, say \def\pList{0.1, 1/6, 0.25, 0.4} (or array, say \def\pListArray{{\pList}}), with xint? Background: I want to keep fractions, like 1/6 in it's original form (not decimal value 0.1666 here). On the other hand, I need to calc 1-<value> too, and I want, in the case of 1/6 the value 5/6 (=1 - 1/6). I have a main document with a lot of xint content and calculations; therefore, for consistency reasons, it should be done with xint (it's clear that there are other packages or methods for this); and: There must be a method in the xint-package that I can't find in the manual. Does anybody know? \documentclass[margin=5pt, varwidth]{standalone} \usepackage{tikz} \usepackage{xintexpr} \begin{document} \def\pList{0.1, 1/6, 0.25, 0.4}% List \def\pListArray{{\pList}} \section{The pList} \pList \section{pgfmath-test for fraction-readout (bad)} p=\pgfmathprint{\pListArray[0]}, q=\pgfmathprint{1-\pListArray[0]} good. But p=\pgfmathprint{\pListArray[1]}, q=\pgfmathprint{1-\pListArray[1]} bad. \section{xint-test for fractions (good), but how to readout?} p=\xinteval{1/6}, q=\xinteval{1-1/6} \end{document}

  • using macros in coordinates is causing node names to be read as functions in tikz
    by Jasper on February 5, 2026 at 11:19 pm

    I'm trying to answer Animating light entry and radiation in a blackbody cavity, but am getting an error that I don't recognize. It's treating hit\hit as a function instead of a node name. It works if I just write it with numbers instead of with \hit. Yes, I know some of my conventions are wrong (e.g., by using one letter macro names). I would fix that after fixing my error which prompted this question. ! Package PGF Math Error: Unknown function `hit6' (in 'hit6'). % Source - https://tex.stackexchange.com/q/759283 % Posted by Sebastiano % Retrieved 2026-02-05, License - CC BY-SA 4.0 % Author: Izaak Neutelings (March 2019) % Inspiration: https://tex.stackexchange.com/questions/203597/automatically-generate-graphics-which-shows-light-diffusion-on-a-rough-surface \documentclass[border=3pt,tikz]{standalone} \usetikzlibrary{decorations.pathmorphing,decorations.markings,calc} % for random steps & snake \usetikzlibrary{arrows.meta} % for arrow size \tikzset{>=latex} % for LaTeX arrow head \tikzstyle{radiation}=[-{Latex[length=2,width=1.5]},red!95!black!50,opacity=0.7,very thin,decorate, decoration={snake,amplitude=0.7,segment length=2,post length=2}] \begin{document} \foreach \c[count = \i from 0] in {6,1,15,5,9,14,2,10,3,4,11,13,1,quack} { \pgfmathsetmacro{\flag}{\i == 0} \pgfmathsetmacro{\flagtwo}{\i == 13} \ifnum\flag=1 \xdef\mylist{\c} \else \ifnum\flagtwo=0 \xdef\mylist{\mylist,\c} \else % nothing \fi \fi \begin{tikzpicture}[scale=1.5,rotate=10] \useasboundingbox (-2,-2) rectangle (2,2); \shade[top color=black!60,bottom color=black!80,shading angle=10] (7:1) arc (7:355:1); \fill[thick,black,postaction=decorate, % rough inner surface decoration={markings,mark=between positions 0.55 and 1 step 0.03 with { \node[transform shape,inner sep=1pt] (hit\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) {}; }}] (7:1) arc (7:353:1) --++ (-7:-0.18) decorate[decoration={random steps,segment length=2,amplitude=1pt}] {arc (-7:-353:0.82)} -- cycle; \draw[yellow] (8:1.5) foreach \hit in {\mylist} { -- (hit\hit .center)}; \ifnum\flagtwo=1 \foreach \ang in {-35,-5,35}{ \draw[radiation] (1,0)++(\ang:0.1 and 0.2) --++ (\ang:0.35); }\fi \end{tikzpicture}} \end{document}

  • Animating light entry and radiation in a blackbody cavity
    by Sebastiano on February 5, 2026 at 9:04 pm

    I am using the code from https://tikz.net/blackbody/ by Izaak Neutelings, which draws a blackbody cavity with an incoming yellow light beam and wavy red arrows representing the emitted radiation. I would like to animate the yellow light beam to show that light enters the cavity, and only afterward make the wavy red arrows appear to represent the radiation. % Author: Izaak Neutelings (March 2019) % Inspiration: https://tex.stackexchange.com/questions/203597/automatically-generate-graphics-which-shows-light-diffusion-on-a-rough-surface \documentclass[border=3pt,tikz]{standalone} \usetikzlibrary{decorations.pathmorphing,decorations.markings,calc} % for random steps & snake \usetikzlibrary{arrows.meta} % for arrow size \tikzset{>=latex} % for LaTeX arrow head \tikzstyle{radiation}=[-{Latex[length=2,width=1.5]},red!95!black!50,opacity=0.7,very thin,decorate, decoration={snake,amplitude=0.7,segment length=2,post length=2}] \begin{document} % BLACK BODY \begin{tikzpicture}[scale=1,rotate=10] \shade[top color=black!60,bottom color=black!80,shading angle=10] % background (7:1) arc (7:355:1); \fill[thick,black,postaction=decorate, % rough inner surface decoration={markings,mark=between positions 0.55 and 1 step 0.03 with { \node[transform shape,inner sep=1pt] (hit\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) {}; }}] (7:1) arc (7:353:1) --++ (-7:-0.18) decorate[decoration={random steps,segment length=2,amplitude=1pt}] {arc (-7:-353:0.82)} -- cycle; \draw[yellow] % connect light ray to random points (8:1.5) -- (hit6.center) -- (hit1.center) -- (hit15.center) -- (hit5.center) -- (hit9.center) -- (hit14.center) -- (hit2.center) -- (hit10.center) -- (hit3.center) -- (hit4.center) -- (hit11.center) -- (hit13.center); \foreach \ang in {-35,-5,35}{ \draw[radiation] (1,0)++(\ang:0.1 and 0.2) --++ (\ang:0.35); } \end{tikzpicture} % BLACK BODY - without infalling light \begin{tikzpicture}[scale=1,rotate=10] \shade[top color=black!60,bottom color=black!80,shading angle=10] % background (7:1) arc (7:355:1); \fill[thick,black,postaction=decorate, % rough inner surface decoration={markings,mark=between positions 0.55 and 1 step 0.03 with { \node[transform shape,inner sep=1pt] (hit\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) {}; }}] (7:1) arc (7:353:1) --++ (-7:-0.18) decorate[decoration={random steps,segment length=2,amplitude=1pt}] {arc (-7:-353:0.82)} -- cycle; \foreach \ang [evaluate={\angin=\ang-180+10*rand; \r=0.76+0.05*rand; \l=0.4+0.02*rand}] in {10,45,100,140,190,240,290,330}{ \draw[radiation] (\ang:\r) --++ (\angin:\l); } \foreach \ang in {-30,0,30}{ \draw[radiation] (1,0)++(\ang:0.05 and 0.16) --++ (\ang:0.35); } \end{tikzpicture} \end{document}

  • Tikzcd's "crossing over" option and transparent backgrounds
    by Ben Steffan on February 5, 2026 at 8:55 pm

    I currently have the following simple setup for producing commutative diagrams using tikzcd and exporting them to .svg's, following the two most popular answers on this question: Put the code for the diagram in a standalone tex file. Compile. Convert to .svg using dvisvgm. This... works, mostly (better ideas are warmly welcome), but I'm running into one issue in particular that is slightly annoying. Consider the following example: \documentclass[crop,tikz]{standalone} \usetikzlibrary{cd} \begin{document} \begin{tikzcd} & & & \{1\} \ar[dd] \ar[dl] \\ \{0\} \ar[rr] \ar[dd] & & \{0, 1\} \\ & \{2\} \ar[dl] \ar[rr] & & \{1, 2\} \ar[dl] \\ \{0, 2\} \ar[rr] & & \{0, 1, 2\} \ar[from=uu, crossing over] \end{tikzcd} \end{document} If you compile this, the resulting pdf looks like this: Great, that looks fantastic. But if you now go and run dvisvgm yourfilenamehere.dvi and drop the resulting svg into something with a non-white background, you get this: This is bad for two obvious reasons: Text and background color are way too similar, and the crossing over arrow now lives on top of a white box. This box is an artifact of the way crossing over works, which simply adds a preaction to the arrow path that draws a background color colored rectangle. Consequently, both problems can be avoided by setting color and background color to something that works, see e.g. this answer. Suppose now, however, that I don't know what color the background of the document/website/etc. the svg will be embedded in has. Perhaps I know that it's going to be a dark background, so that setting the text color to white will take care of the first issue, but unless I know the precise shade of the background I can't set the crossing over box' color to perfectly match. My question, thus, is whether there is a (nice) way to solve this second issue when the final background color is not precisely known (if you have a way to dynamically alter the text color, I'd be happy to hear about it as well). (By "nice" here I mean that e.g. it's obviously possible to draw the two "pieces" of the arrow being crossed over separately and avoid crossing over entirely, but this seems to annoying to do in general unless there is some way to package it up into a flexible macro/tikz key).

  • Make perfect circular diagrams
    by Fran on February 5, 2026 at 12:23 pm

    I know that I can make circular diagrams with the nice smartdiagram package, but arrows do not fit perfectly in a imaginary circle. In fact, the diagram is far from a circle when there are only two or three nodes: \documentclass{standalone} \usepackage{smartdiagram} \begin{document} \smartdiagramset{ connection color=red, module shape= circle, circular distance=2cm, uniform color list=white for 6 items, uniform arrow color=true, arrow color=black} \smartdiagram[circular diagram:clockwise]{foo, bar} \end{document} I know also that there are several examples in this site about making circular diagrams without this package, but translating these examples to diagrams with a different numbers of nodes is complex, so I tried an automated solution with tikz (without really knowing what I was doing, I have to admit) so that I only have to modify a list of nodes in \mylist and little more to obtain the result: \documentclass[border=2mm]{standalone} \usepackage{tikz} \usetikzlibrary{arrows.meta} \begin{document} \begin{tikzpicture}[ > = Stealth, every node/.style = {circle, draw, thick, minimum width=1cm, align=center} ] \def\mylist{foo, bar, baz} % play with this \foreach \x [count=\i from 1] in \mylist {\xdef\n{\i}} \def\radio{2cm} % and this if needed \foreach \texto [count=\i from 0] in \mylist{ \pgfmathsetmacro\ang{-\i*360/\n} \node (n\i) at (\ang:\radio) {\texto}; } \foreach \dummy [count=\i from 0] in \mylist{ \pgfmathsetmacro\j{int(mod(\i+1,\n))} \pgfmathsetmacro\angini{-\i*360/\n} \pgfmathsetmacro\angfin{-\j*360/\n} \pgfmathsetmacro\outang{mod(\angini - 90 + 720, 360)} \pgfmathsetmacro\inang {mod(\angfin + 90 + 720, 360)} \draw[->, thick, line width=1.4pt] (n\i) to[out=\outang, in=\inang, looseness=.9] (n\j); % and with the looseness } \end{tikzpicture} \end{document} Mainly it works. The problem is that like in smartdiagram, the arrows don't perfectly follow an imaginary circle, that was the idea behind getting involved in this business. Playing with looseness is possible to correct a bit the curvature of the arrows, but it's tedious and the result is never perfect. So, the result should be ideally near to the image below (that I modified manually in Inkscape) and still require minimal settings to adapt the code to diagrams of n nodes. Fixes of the MWE as well as alternative approaches are welcome. Edit Thank you all for the excellent suggestions. This time, I am truly sorry I can only accept one.

  • Problem with the position of a graph (pgfplots)
    by Octavius on February 5, 2026 at 12:36 am

    in the following code and in the attached image, the graph becomes misaligned. Could you please give me an idea on how to fix it? \documentclass{article} \usepackage{graphicx} % Required for inserting images \newcommand{\ocultar}[1]{} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{pdfpages} \usepackage{hyperref} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage[utf8]{inputenc} \usepackage[spanish]{babel} \usetikzlibrary{angles, quotes} \usepackage{fancyhdr} \usepackage{graphicx} \usepackage{array} \begin{document} \begin{center} \begin{tabular}{>{\centering}m{5cm} >{\centering}m{5cm} >{\centering}m{5cm}} % CRECIENTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[red, thick] {x+1}; \end{axis} \end{tikzpicture} & % DECRECIENTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[blue, thick] {-x+3}; \end{axis} \end{tikzpicture} & % CONSTANTE \begin{tikzpicture} \begin{axis}[ axis lines=middle, xmin=-3,xmax=6, ymin=-3,ymax=6, grid=both, width=5cm, height=5cm, ticks=none ] \addplot[black, thick] {3}; \end{axis} \end{tikzpicture} \\[2mm] \fbox{\begin{minipage}{4.5cm} \centering \textbf{Creciente.}\\ En este caso su pendiente\\ es \textcolor{red}{\textbf{POSITIVA}.} \end{minipage}} & \fbox{\begin{minipage}{4.5cm} \centering \textbf{Decreciente.}\\ En este caso su pendiente\\ es \textcolor{blue}{\textbf{NEGATIVA}.} \end{minipage}} & \fbox{\begin{minipage}{4.5cm} \centering \textbf{Constante.}\\ En este caso su pendiente\\ es \textbf{CERO}. \end{minipage}} \end{tabular} \end{center} \end{document}

  • Drawing a pulley system
    by Fatai Bakare on February 1, 2026 at 8:32 am

    I need to draw a pulley system as in the figure. How can I do that? Specific information about the figure: A block of mass Mo is on a horizontal surface and attached by a string to a hanging block, also of mass Mo , as shown in the figure. Friction between the block and the horizontal surface is negligible. The masses of the string and pulley are negligible, and the pulley can rotate with negligible friction around its axle.

  • Incorrect spath3 "split at" method with a continued line?
    by Explorer on September 19, 2025 at 7:10 am

    Learning from this link: I have the following code: \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{spath3} \begin{document} \begin{tikzpicture} \draw[spath/save=path,ultra thick,blue!30] (0,0) -- (4,2); \draw[spath/split at keep start={path}{1/3},spath/use=path]; \draw[spath/split at keep end={path}{2/3},spath/use=path]; \draw[spath/split at keep middle={path}{1/3}{2/3},spath/use=path,densely dashed]; \end{tikzpicture} \begin{tikzpicture} \draw[spath/save=path,ultra thick, red!30] (0,0) -- (1,1) -- (2,-1) -- (3,4) -- (4,0); \draw[spath/split at keep start={path}{1/3},spath/use=path]; \draw[spath/split at keep end={path}{2/3},spath/use=path]; \draw[spath/split at keep middle={path}{1/3}{2/3},spath/use=path,densely dashed]; \end{tikzpicture} \end{document} In the first figure, the "dashed" line shown exactly at 1/3 and 2/3. However, in the second, if the path is longer, it seemed not dealing right? Is that possible to fix that: for the whole path, only the middle "1/3" length's path is "dashed"?

  • Issue: Unable to Display Text Below TikZ Code in LyX"
    by Evya1 on January 20, 2024 at 10:35 am

    I am currently facing a challenge in LyX where, after typing several lines of text, I insert TikZ code either inside a TeX box or directly into the apex preamble. However, I have observed that the text following the TikZ code is not visible. In the case of placing the code in the preamble, none of the text I have written in the document is visible. I am seeking assistance in resolving this issue and understanding how to ensure the proper display of text below inserted TikZ code in LyX. Any guidance or solutions would be greatly appreciated. LyX file: #LyX 2.3 created this file. For more info see http://www.lyx.org/ \lyxformat 544 \begin_document \begin_header ... \end_header \begin_body \begin_layout Standard Text here. 1 Algorithms - question 1 1 . ~~~Trying to show the figure here ~~~ ~~~ Text of the solution that isn't shown in rendered pdf~~~ \end_layout \end_body \end_document LaTeX preamble: \usepackage{autobreak} \usepackage{fontspec} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{autobreak} \usepackage{xcolor} \usepackage{amssymb} \usepackage{polyglossia} \usepackage{tikz} \setmainlanguage{hebrew} \setotherlanguage{english} \spaceskip=1\fontdimen2\font plus 1\fontdimen3\font minus 1.5\fontdimen4\font \everymath{\, } \usepackage{xcolor} \definecolor{blue}{RGB}{14,107,217} \definecolor{green}{RGB}{0,158,40} \definecolor{red}{RGB}{235,16,16} \definecolor{brown}{RGB}{164,66,0} \definecolor{orange}{RGB}{231,135,26} \definecolor{purple}{RGB}{94,53,177} \usepackage{amssymb} \renewcommand{\qedsymbol}{$\blacksquare$} \pagestyle{empty} \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{arrows} \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{arrows} \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{arrows} \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{arrows, positioning} \usepackage{tikz} \usetikzlibrary{arrows, positioning} \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{arrows, positioning} \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{arrows, positioning} \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{arrows, positioning} \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{arrows, positioning} \begin{document} \begin{tikzpicture}[->,>=stealth',auto,node distance=2.5cm, thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries, minimum size=1cm}, align=center] \node[main node] (s) {$s$}; \node[main node] (v1) [below right=0.8cm and 1.8cm of s] {$v_1$}; \node[main node] (v2) [above right=0.8cm and 1.8cm of s] {$v_2$}; \node[main node] (vn-3) [right=1.2cm of v1] {$v_{n-3}$}; \node[main node] (vn-2) [right=1.2cm of v2] {$v_{n-2}$}; \node[main node] (t) [below right=0.8cm and 1.8cm of vn-2] {$t$}; \draw [->] (s) -- (v1); \draw [->] (s) -- (v2); \draw [->] (vn-3) -- (t); \draw [->] (vn-2) -- (t); \draw [dashed] [->,blue] (v1) -- (vn-2); \draw [dashed] [->,blue] (v2) -- (vn-3); \draw [dashed, ->, bend right] (v1.north) to (v2.south); \draw [dashed, ->, bend] (v2.south) to (v1.north); \draw [dashed, ->, bend right] (vn-3.north) to (vn-2.south); \draw [dashed, ->, bend] (vn-2.south) to (vn-3.north); % Add dashed lines to represent the cutted paths \draw [dashed] (s) -- (v1); \draw [dashed] (s) -- (v2); \draw [dashed] (v1) -- (vn-3); \draw [dashed] (v2) -- (vn-2); \draw [dashed] (vn-3) -- (t); \draw [dashed] (vn-2) -- (t); \end{tikzpicture} \end{document}

  • Grid in LaTeX help
    by Amagoo on February 8, 2023 at 11:26 am

    Hi am new to latex and trying to recreate the grid as shown in the image, any help at all would be greatly appreciated

  • Drawing a simple Markov chain in a "triangle inequality" configuration
    by The Pointer on October 17, 2022 at 10:24 pm

    I'm trying to use Tikz to graph a simple Markov chain with three nodes. The first node is labelled s = 1, the second node is labelled s = 2, and the third node is labelled s = 3. All are connected via straight, undirected edges. But the problem is that I want the chain in a "triangle inequality" kind of shape, where node s = 2 is between s = 1 and s = 3, but off to the side a bit, so that it has a kind of triangle shape. This image from the Wikipedia article for triangle inequality illustrates what I mean: The nodes would be the vertices. I can't find any tutorials that show how to do such a thing. How is this done? EDIT The closest demonstrations I can find are things like this: (From https://ai.plainenglish.io/fraudulent-transaction-detection-using-markov-model-from-scratch-b26e6bf9bc0d) But I want a configuration like this: (From https://www.semanticscholar.org/paper/Inference-and-minimization-of-hidden-Markov-chains-Gillman-Sipser/88e08bd20b2ffc201eb92f3d073e06df92bb9fad) EDIT2 I tried the following, but it doesn't seem to compile: % Author: Till Tantau % Source: The PGF/TikZ manual \documentclass{article} \usepackage{pgf} \usepackage{tikz} \usetikzlibrary{arrows,automata} \usepackage[latin1]{inputenc} \begin{document} \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick] \tikzstyle{every state}=[fill=red,draw=none,text=white] \node[initial,state] (A) {$q_a$}; \node[state] (B) [above right of=A] {$q_b$}; \node[state] (C) [right of=A] {$q_c$}; \path (A) edge node (B) edge node (C) (B) edge node (C) \end{tikzpicture} \end{document} EDIT3 Got it: % Author: Till Tantau % Source: The PGF/TikZ manual \documentclass{article} \usepackage{pgf} \usepackage{tikz} \usetikzlibrary{arrows,automata} \usepackage[latin1]{inputenc} \begin{document} \begin{tikzpicture}[shorten >=1pt,auto,node distance=2.8cm, semithick] \tikzstyle{every state}=[fill=red,draw=none,text=white] \node[initial,state] (A) {$s = 1$}; \node[state] (B) [above right of=A] {$s = 2$}; \node[state] (C) [below right of=B] {$s = 3$}; \path (A) edge node {a1} (B) edge node {a2} (C) (B) edge node {a3} (C); \end{tikzpicture} \end{document} But for some reason it won't let me use a_1, a_2, a_3, so I have to use a1, a2, a3.

  • Absolute value of a function in tikz
    by UserA on December 2, 2021 at 2:27 pm

    Being a beginner, I'm having difficulty in plotting |sinx|. Can anyone help me with plotting y=|sinx| in [0,2pi] and y=0 elsewhere in tikz?

  • Draw a PhotoGate apparatus
    by Jorge on November 15, 2017 at 2:54 pm

    Is there a way to improve a schematic representation of PhotoGate apparatus? These instruments are widely used in Physics, so it would be interesting to get a good representation of it. I would like to ask for a Tikz solution and, if possible, for improvements in the artistic eye. My first code: \startMPcode path left_cell, right_cell, p, ball, texas; numeric u,v; u := 1cm; v:=.5cm; picture photogate, photogate_inactive; photogate := image ( texas := unitsquare xscaled 2v yscaled 2u shifted(4u,v); ball := fullcircle scaled 1.5cm; left_cell := unitsquare xscaled v yscaled u; right_cell := left_cell shifted (2.5u, .5v); p := (center left_cell) -- (center right_cell); draw left_cell; draw right_cell; draw p dashed evenly withcolor red; draw texas; draw urcorner left_cell .. urcorner left_cell + (0,2v) .. urcorner right_cell + (0,1.5v) .. center texas; draw urcorner right_cell .. center texas + (0,-.1u); fill ball shifted (center p + (0,3v)) withcolor red; draw ball shifted (center p + (0,3v)); ); photogate_inactive := image ( texas := unitsquare xscaled 2v yscaled 2u shifted(4u,v); ball := fullcircle scaled 1.5cm; left_cell := unitsquare xscaled v yscaled u; right_cell := left_cell shifted (2.5u, .5v); p := (center left_cell) -- (center right_cell); draw left_cell; draw right_cell; %draw p dashed evenly withcolor red; fill ball shifted center p withcolor red; draw ball shifted (center p); draw texas; draw urcorner left_cell .. urcorner left_cell + (0,2v) .. urcorner right_cell + (0,1.5v) .. center texas; draw urcorner right_cell .. center texas + (0,-.1u); ); draw photogate; draw photogate_inactive shifted (7cm , 0); \stopMPcode UPDATE (after Thurston suggestions) My new code: \startMPcode numeric u,v; u := 1cm; v:=.5cm; vardef photogate_base (expr ative) = path left_cell, right_cell, p, ball, texas; texas := unitsquare xscaled 2v yscaled 2u shifted(4u,v); ball := fullcircle scaled 1.5cm; left_cell := unitsquare xscaled v yscaled u; right_cell := left_cell shifted (2.5u, .5v); p := (center left_cell) -- (center right_cell); image ( draw left_cell; draw right_cell; draw urcorner left_cell .. urcorner left_cell + (-1u,3v) .. urcorner right_cell + (0,2v) .. center texas + (0,.6u) cutafter texas; draw urcorner right_cell .. urcorner right_cell + (0,.001v) .. center texas cutafter texas; if ative == 1: draw ball shifted (center p + (0,2.5v)); fill ball shifted (center p + (0,2.5v)) withcolor red; draw p dashed evenly withcolor red; else: fill ball shifted (center p + (0,.5v)) withcolor red; draw ball shifted (center p + (0,.5v)); fi; draw texas;) enddef; draw photogate_base(1); draw photogate_base(0) shifted (7cm , 0); \stopMPcode

  • Drawing an irregular shape for hypothesis space representation
    by Metamatics on November 13, 2016 at 1:35 pm

    Is there any way to reproduce the picture below with tikz? I am relatively unfamiliar with tikz and failed to reproduce anything that looks at least partly like the following representation. This is were I've got until now: \documentclass{article} \usepackage{tikz} \usetikzlibrary{hobby} \begin{document} \begin{tikzpicture}[use Hobby shortcut,closed=true] \draw (-3.5,0.5) .. (-3,2.5) .. (-1,3.5).. (1.5,3).. (4,3.5); \draw (-1,1.5) ellipse (57pt and 33pt); \draw [fill=black] (-0.5,1.5) circle (1.5pt); \draw[color=black] (-0.5,1.2) node {$f$}; \draw [fill=gray] (0,1.2) circle (1.5pt); \draw[color=gray] (0,0.9) node {$h_1$}; \draw [fill=gray] (-1.2,2) circle (1.5pt); \draw[color=gray] (-1.2,2.3) node {$h_2$}; \draw [fill=gray] (-1,1.35) circle (1.5pt); \draw[color=gray] (-1.3,1.35) node {$h_3$}; \end{tikzpicture} \end{document} The two most challenging tasks are to reproduce this irregular shape in the same form and to draw these irregular arrows.

  • How to draw random simple closed smooth curves but with the same perimeter?
    by kiss my armpit on December 8, 2014 at 2:59 am

    I want to draw some random simple smooth closed curves. Each smooth curve must have the same perimeter but different area. See the following figure to illustrate what I meant clearly. Each smooth curve is assumed to have the same perimeter. How to do this with PSTricks (preferred) or TikZ or Metapost or Asymptote? The following template is provided to save your time. \documentclass{pstricks,border=12pt,12pt} \begin{document} \psLoop{10}{% \begin{pspicture}(-5,-5)(5,5) \end{pspicture}} \end{document}