TikZ
- circuitikz: width, height and pin-distance of a 'op amp'by cis on January 5, 2026 at 1:27 pm
I want to create a breadboard whose x-slot spacing matches the pin spacing of a muxdemux (this was done here); and whose y-slot spacing matches the pin spacing of an op amp. An image for clarification: I can approximate the y-direction by trial and error, using \pgfmathsetlengthmacro\OApin{% 'op amp' pin width \bl*\ctikzvalof{tripoles/op amp/width}*0.3*0.5} But I would like to do this accurately and precisely. In short: I need height, width, and pin spacing of an op amp from the package-keys. (Unfortunately, these keys are usually well hidden and not very self-explanatory.) \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage{circuitikz} \def\ShowBreadBoard{1} % Breadboard 1/2 ====================== % Default of bipoles/length ================= \pgfmathsetlengthmacro\bl{\UseName{pgf@circ@Rlen}}% default 1.4cm %%%%%%%%%% Problems here %%%%%%%%%%% % Breadboard y - measures of 'op amp' ================= \pgfmathsetlengthmacro\OApin{% 'op amp' pin width \bl*\ctikzvalof{tripoles/op amp/width}*0.3*0.5} \pgfmathsetlengthmacro\OAh{% 'op amp' height \bl*\ctikzvalof{tripoles/op amp/height}} \pgfmathsetlengthmacro\OAw{% 'op amp' width \bl*\ctikzvalof{tripoles/op amp/height}*5/6+0*\pgflinewidth/cos(45)} %%%%%%%%%%%%%%%%%%%%%%%%% % Breadboard x - measures of 'MuxDemux' ================= \pgfmathsetlengthmacro{\basemuxlen}{\bl *\ctikzvalof{multipoles/muxdemux/base len} *\ctikzvalof{muxdemuxes/scale}} \pgfmathsetlengthmacro{\MUXw}{\basemuxlen*6}%w=6, muxdemux-width %\pgfmathsetlengthmacro{\MUXh}{\basemuxlen*4}%Lh=4, muxdemux-height \pgfmathsetlengthmacro{\MUXp}{\MUXw/3}% bottom pin distance of muxdemux \begin{document} \begin{circuitikz}[] % Breadboard 2/2 ================ \begin{scope}[font=\footnotesize\ttfamily] \pgfmathsetlengthmacro\u{\MUXp/4}% x-unit-length \pgfmathsetlengthmacro\v{\OAh/4}% y-unit-length \def\X{x} \def\Y{y}% letters for coordinates \foreach \x in {0,...,26}{%% \foreach \y in {0,...,6}{% \ifnum\ShowBreadBoard=1 %%%%%%%%% \pgfmathtruncatemacro\Xt{mod(\x,2)==0 ? 1 : 0}% show x-coordinate test \pgfmathtruncatemacro\Yt{mod(\y,2)==0 ? 1 : 0}% show y-coordinate test \fill[gray] (\u*\x,-\y*\v) circle[radius=0.65pt] coordinate[label=](\X\x\Y\y); \ifnum\y=0 \node[above, red] at (\X\x\Y\y) {\ifnum\Xt=1 \x\fi};\fi \ifnum\x=0 \node[left, red] at (\X\x\Y\y) {\ifnum\Yt=1 \y\fi};\fi \draw[red, shorten <=2pt] (x0y0) -- +(135:0.75) node[midway, above]{x} node[near end, below]{y}; \else% \coordinate[](\X\x\Y\y) at (\u*\x,-\y*\v); \fi%%%%%%%%%%%%%% }}% %% %\node{\OAw, \OAh};% test %\draw (x0y0) circle(1mm); % test \end{scope}% ===================== \node[op amp](opamp) at (x8y3) {}; \draw (x15y3) to[L, color=pink] (x22y3); \end{circuitikz} \end{document}
- How to shorten the sliding rheostat's wire length in circuitikz package?by Explorer on January 5, 2026 at 7:45 am
What I want to achieved is as below: I have the following code: \documentclass[border=5pt]{standalone} \usepackage{circuitikz} \begin{document} \begin{circuitikz}[european] \draw(0,0) to [rmeter,t=A] (0,2) to [R,l_=$R$](3,2) to [pR,l_=$R'$,n=pr] (4.1,2); \draw(0,0) to [normal open switch,l_=$S$] (6,0) |-(pr.wiper); \end{circuitikz} \end{document} it gives the similar result: However, the righthand of sliding rheostat's length is control in manual, but guess the coordinate (4.1,2), which is not elegant. I have consulted the manual, but found no similar components. Is that better method to achieve the desird result?
- circuitikz: set 'rounded corners' of a 'oscopeshape' to a smaler valueby cis on January 4, 2026 at 11:23 pm
Due to a chat-talk with @Rmano, I asked myself wether there is a methode to set the rounded corners of a oscopeshape to 0pt or to a very small value. The rounded corners can become weird, if I set a small scale: \documentclass[margin=10pt]{standalone} \usepackage{circuitikz} \begin{document} \begin{circuitikz}[font=\footnotesize] \node[oscopeshape] (A){scale=1}; \node[oscopeshape, right of=A, scale=0.5](B) {scale=0.5}; \node[oscopeshape, right of=B, scale=0.35] {scale=0.35}; \end{circuitikz} \end{document}
- circuitikz: width (height) and pin-distance of a 'muxdemux'by cis on January 4, 2026 at 4:48 pm
How do I get these two lengths? By the way: a) I don't need the height right now, but I assume the extraction method would be the same; so it wouldn't hurt to have it... b) I know how to do it with the calc library. However, it would be better if I could get the dimensions directly from the circuitikz package, without having to measure them after drawing. \documentclass[margin=15pt]{standalone} \usepackage{circuitikz} \begin{document} \tikzset{ circuitikz/muxdemux/outer label font={\tiny\ttfamily\color{blue}}, mychip/.style={muxdemux,% ===================== muxdemux def={ Lh=4, Rh=4, w=6,% sizes NR=0, NL=5, NB=3, NT=3,}, muxdemux label={ %T1=T1, T2=T2, T3=T3, B1=B1, B2=B2, B3=B3, BR1=br1, BL1=bl1, BR2=br2, BL2=bl2, BR3=br3, BL3=bl3,% %TR1=tr1, TL1=tl1, TR2=tr2, TL2=tl2, TR3=tr3, TL3=tl3,% LU1=lu1, LD1=ld1, LU2=lu2, LD2=ld2, LU3=lu3, LD3=ld3, LU4=lu4, LD4=ld4, LU5=lu5, LD5=ld5, }, draw only top pins={}, append after command={ \pgfextra \def\fg{\tikzlastnode} % Contacts annotations ============== \foreach \x in {1,2,3}{%% \node[bnc, anchor=zero, rotate=-90](Contact\x) at (\fg.blpin 5 -| \fg.btpin \x) {}; \draw[] (Contact\x) -- (\fg.bbpin \x); }%% \endpgfextra }, },% ===================== } \begin{circuitikz}[>=latex] \node[mychip](FG){chip}; \draw[purple, <->] (FG.north west) -- (FG.north east) node[midway, fill=white, inner sep=0pt]{w=? pt}; \draw[orange, <->] (FG.bpin 1) -- (FG.bpin 2) node[midway, below]{p=? pt}; \end{circuitikz} \end{document}
- How to test if a pgfkey is emptyby Guidone on January 4, 2026 at 4:12 pm
I have already checked the answers to a similar question, but it uses a pattern different from mine and, therefore, totally unfamiliar to me. Elaborating on the answers to a question of mine posted here, I came up with the following MWE: \NeedsTeXFormat{LaTeX2e} \ProvidesClass{argumap}[2026/01/03 v.0.0 Argument Mapping] \LoadClass[11pt]{extarticle} \RequirePackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \setmainfont{Brill} \RequirePackage{euler-math} \newfontfamily{\supscriptfont}{Euler Math}[Scale=0.55] \RequirePackage{polyglossia} \setdefaultlanguage{italian} \setotherlanguage[hyphenation=liturgical, usej=true, prosodicshorthands=true]{latin} %=================% % Document layout % %=================% % Page \RequirePackage{geometry} \geometry{a4paper,margin=20mm} \pagestyle{plain} \setlength{\parindent}{0pt} % Line spacing: 1.3 \RequirePackage{setspace} \setstretch{1.2} % Two-column engine \RequirePackage{paracol} %=================% % Utilities % %=================% %------------------ % Control Flow %------------------ \RequirePackage{xifthen} \RequirePackage{xstring}% used to operate on a string %------------------ % Graphics %------------------ \RequirePackage{graphicx} \RequirePackage{tikz} \usetikzlibrary{% calc,arrows.meta,% positioning,% decorations.pathreplacing} % Styles \tikzset{ argStmnt/.style={ circle, draw, inner sep=0pt, minimum size=2.2em, font=\normalsize, }, arganDep/.style={ -{Latex[length=2.2mm,width=1.6mm]}, line width=0.4pt }, } \newrobustcmd{\emptyKey}{} \newrobustcmd{\elemPos}{} \pgfkeys{% /gstmnt/.is family, /gstmnt/.cd, name/.store in=\elemName, depend from/.store in=\dependFrom, depend from/.default={}, from/.store in=\dirFrom, to/.store in=\dirTo, element@pos/.style={}, south of/.code={% \pgfqkeys{/gstmnt}{% element@pos/.style={below=of #1}, }% }, north of/.code={% \pgfqkeys{/gstmnt}{% element@pos/.style={above=of #1}, }% }, west of/.code={% \pgfqkeys{/gstmnt}{% element@pos/.style={left=of #1}, }% }, east of/.code={% \pgfqkeys{/gstmnt}{% element@pos/.style={right=of #1}, }% },% name,depend from,from,to } \NewDocumentCommand{\graphStmnt}{O{} m}{ \pgfkeys{/gstmnt/.cd, #1} \typeout{Node Name=[\elemName]} \typeout{First Call of Depend From=[\dependFrom]} \node[argStmnt, /gstmnt/element@pos,] (\elemName) {$#2$}; \ifthenelse{\isempty{\dependFrom}} {\typeout{Second Call of Depend From=[\dependFrom]}} {\draw[arganDep] (\dependFrom.\dirFrom) -- (\elemName.\dirTo);} % \IfStrEq{\dependFrom}{\emptyKey}% % {\typeout{Second Call of Depend From=[\dependFrom]}} % {\draw[arganDep] (\dependFrom.\dirFrom) -- (\elemName.\dirTo);} } \NewDocumentEnvironment{argugraph}{O{12mm} +b}{ \par\centering% \begin{tikzpicture}[node distance=#1]% #2 }{% \end{tikzpicture}\par} When I compile the following example: \documentclass{argumap} \begin{document} \begin{argugraph} \graphStmnt[name=A]{A} % \graphStmnt[name=A, depend from={}]{A}%same result as above \graphStmnt[name=B, south of=A, depend from=A, from=south, to=north]{B} \graphStmnt[name=C, north of=A, depend from=A, from=north, to=south]{C} \graphStmnt[name=D, west of=A, depend from=A, from=west, to=east]{D} \graphStmnt[name=E, east of=A, depend from=A, from=east, to=west]{E} \graphStmnt[name=F, south of=D, depend from=D, from=south, to=north]{F} \end{argugraph} \end{document} I get the following result: And compiling error: Node Name=[A] First Call of Depend From=[] ! Package pgf Error: No shape named `' is known. See the pgf package documentation for explanation. Type H <return> for immediate help. ... l.18 \end {argugraph} So, for some, to me, unknown reason, when I try to test if \dependFrom is empty, even if I haven't passed any value to the key, the test fails, meaning that it goes to the "else" statement, hence the failure to display the message «Second Call of Depend From=[\dependFrom]». Why? Any idea? These pgfkeys are very nice, but, for me, very challenging to handle, and the manual doesn't help me much.
- How to use specific height in tikz tcolorboxby user386618 on January 4, 2026 at 9:53 am
I wanted to set the coordinate that it's height is one third of a box that consists of 1 line, but tikz don't understand. What to do? \documentclass[10pt]{book} \usepackage[english]{babel} \usepackage[most]{tcolorbox} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tcolorbox}[enhanced, width=\linewidth, frame hidden, interior hidden, overlay={\draw[x=\dimexpr\ht\strutbox+\dp\strutbox\relax, y=\dimexpr\ht\strutbox+\dp\strutbox\relax] (1/3,0)--(0,1/3)--($(frame.north west)-(0,1/3)$)--($(frame.north west)+(1/3,0)$)--($(frame.north east)-(1/3,0)$)--($(frame.north east)-(0,1/3)$)--($(frame.south east)+(0,1/3)$)--($(frame.south east)-(1/3,0)$)--cycle;}] Smth \end{tcolorbox} \end{document} I want the shape to be like a part of regular octagon like below so for one line is more like a stretched regular octagon, i can approximate but want to be more precise
- Space before grid [closed]by Тимур Черняев on January 4, 2026 at 1:17 am
I'm trying to create a worksheet-like template, and I run into some issues with the grid. Really big space pops up, and I don't know how to get rid of it. I'm using tikz. Here's the screenshot of the problem and fragments of code I believe will be useful. Thanks in advance! % ========================================================= % ==================== GRID SETTINGS ====================== % ========================================================= \newlength{\gridsize} \setlength{\gridsize}{5mm} \newcommand{\gridcolor}{black!40} \newcommand{\gridlinewidth}{0.3pt} ... % ========================================================= % =================== PAGE GRID FILL ====================== % ========================================================= \newcommand{\gridblock}[1]{% \noindent \begin{tikzpicture} \pgfmathsetlengthmacro{\gridheight}{#1\textheight} \pgfmathsetlengthmacro{\gridwidth}{\textwidth} \pgfmathsetlengthmacro{\cell}{\gridsize} \pgfmathsetmacro{\Nx}{ceil(\gridwidth/\cell)} \pgfmathsetmacro{\Ny}{ceil(\gridheight/\cell)} % Горизонтальные линии \foreach \i in {0,...,\Ny} { \draw[color=\gridcolor, line width=\gridlinewidth] (0, \i*\cell) -- (\gridwidth, \i*\cell); } % Вертикальные линии \foreach \i in {0,...,\Nx} { \draw[color=\gridcolor, line width=\gridlinewidth] (\i*\cell, 0) -- (\i*\cell, \gridheight); } \end{tikzpicture}% } % ========================================================= % ====================== PROBLEM+GRID ===================== % ========================================================= \newlength{\problemgridsep} \setlength{\problemgridsep}{2pt} \newenvironment{problemwithgrid}[1]{ \def\currentgridfraction{#1} \begin{problem} }{ \end{problem} \vspace{2pt} \gridblock{\currentgridfraction} }
- Are there any tikz library or TeX package to create maps?, with items like rivers, trees, level curves, similar to RPG maps?by Mika Ike on January 3, 2026 at 6:45 pm
From time to time I search if there is a practical/eficient way to create maps, similar to the next ones, even with a terrain texture or even contour level. Are there any tikz library appropiate for this purpose? Images from https://rpgmapsforge.com/
- How to pass relative coordinates to a \node via \pgfkeysby Guidone on January 3, 2026 at 3:20 pm
What I am trying to achieve is to set a pgfkey (south of, for example), which would be a placeholder for the native option below=of <node> and to pass it to a custom command. Here is the working example: \NeedsTeXFormat{LaTeX2e} \ProvidesClass{argumap}[2026/01/03 v.0.0 Argument Mapping] \LoadClass[11pt]{extarticle} \RequirePackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \setmainfont{Brill} \RequirePackage{euler-math} \newfontfamily{\supscriptfont}{Euler Math}[Scale=0.55] \RequirePackage{polyglossia} \setdefaultlanguage{italian} \setotherlanguage[hyphenation=liturgical, usej=true, prosodicshorthands=true]{latin} %=================% % Document layout % %=================% % Page \RequirePackage{geometry} \geometry{a4paper,margin=20mm} \pagestyle{plain} \setlength{\parindent}{0pt} % Line spacing: 1.3 \RequirePackage{setspace} \setstretch{1.2} % Two-column engine \RequirePackage{paracol} %=================% % Utilities % %=================% %------------------ % Control Flow %------------------ \RequirePackage{xifthen} \RequirePackage{xstring}% used to operate on a string %------------------ % Graphics %------------------ \RequirePackage{graphics} \RequirePackage{tikz} \usetikzlibrary{% calc,arrows.meta,% positioning,% decorations.pathreplacing} % Styles \tikzset{ argStmnt/.style={ circle, draw, inner sep=0pt, minimum size=2.2em, font=\normalsize, }, arganDep/.style={ -{Latex[length=2.2mm,width=1.6mm]}, line width=0.4pt }, } \pgfkeys{% /argumap/.is family, /argumap/.cd, name/.store in=\elemName, position/.default={}, position/.store in=\elemPos, position,name } \NewDocumentCommand{\graphStmnt}{O{} m}{ \pgfkeys{/argumap/.cd, #1} \typeout{element name=[\elemName]} \ifthenelse{\isempty{\elemPos}} {\node[argStmnt] (\elemName) {$#2$};} { \typeout{element position=[\elemPos]} \node[argStmnt, \elemPos] (\elemName) {$#2$};} } \NewDocumentEnvironment{argugraph}{+b}{ \par\centering% \begin{tikzpicture}% #1 }{% \end{tikzpicture}\par} Here is the implementing example: \documentclass{argumap} \begin{document} \begin{argugraph} \graphStmnt[name=A]{A} \graphStmnt[name=B, position={below=of A}]{B} \end{argugraph} \end{document} When I compile it, I get the following error: element name=[A] element position=[] element name=[B] element position=[below=of A] ! Package pgfkeys Error: I do not know the key '/tikz/below=of A' and I am goin g to ignore it. Perhaps you misspelled it. See the pgfkeys package documentation for explanation. Type H <return> for immediate help. So, question is, how can I pass native /tikz options such as below=of to a custom document or environment with custom-defined options? Thanks for the help. Oh, and happy new year.
- TikZ: dot-syntax for coordinates / anchors (.) [e.g. (Box.A)]by cis on January 3, 2026 at 12:25 pm
If I set some coordinates inside a node named (Box) (with path picture), say (A),(B),(C). How can I get the (from other codes known) (Box.A) syntax? \documentclass[margin=5pt]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[ test/.style={minimum width=3cm, minimum height=2cm, fill=lightgray, draw, path picture={%% \draw[purple] (path picture bounding box.200) -- (path picture bounding box.-20) coordinate[pos=0.2, label=center:A](A) coordinate[pos=0.5, label=center:B](B) coordinate[pos=0.8, label=center:C](C); },%% }, ] \node[test](Box){}; \draw[red ,<-] (A) -- +(-135:1) node[right]{$\to$A}; % Needed: (Box.A), (Box.B), ... % \draw[red ,<-] (Box.A) -- +(-135:1) node[right]{$\to$A}; % \draw[red ,<-] (Box.B) -- +(-45:1) node[right]{$\to$B}; \end{tikzpicture} \end{document}
- TikZ: overlay labels or nodes or unclip 'path picture'by cis on January 3, 2026 at 9:56 am
Is there a way, to overlay labels or nodes inside a path picture, so that I can see the text? \documentclass[margin=5pt]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[ test/.style={minimum width=6cm, minimum height=4cm, fill=lightgray, path picture={%% \draw[blue] (path picture bounding box.west) -- (path picture bounding box.east) coordinate[pos=0.3, label=center:B1](B1) coordinate[pos=0.6, label=center:B2(all good)](B2) coordinate[pos=0.9, label=center:B2](B3); % How to overlay labels here? ============= \draw[red] (path picture bounding box.north west) -- (path picture bounding box.north east) coordinate[pos=0.3, label={[overlay]center:A1}](A1)% no effect coordinate[pos=0.6, label=center:A2(not good)](A2) coordinate[pos=0.9, label=center:A2](A3); },%% }, ] \node[test]{}; \end{tikzpicture} \end{document}
- TikZ: grid at certain x- and y-positionsby cis on January 3, 2026 at 9:45 am
I want to create a 6x5 dotted grid over an area with clearly defined width and height (\w and \h). Can I configure the grid to only display points at the intersections of the horizontal and vertical lines? I only get that with dash pattern=on 0pt off \w/6, for the x-positions. What do I have to do? By the way: I'm wondering, as a task out of pure interest, how one can adjust the grid. It's clear how to manually create the image using foreach-loops. \documentclass[margin=5pt]{standalone} \usepackage{tikz} \pgfmathsetlengthmacro\w{2cm} \pgfmathsetlengthmacro\h{3.2cm} \begin{document} \begin{tikzpicture}[] \draw[] (0,0) rectangle (\w,\h) node[anchor=south east, align=center]{ Dots only at \\ all intersections \\ of the horizontals \\ and the verticals}; \draw[orange, xstep=\w/6, ystep=\h/5] (0,0) grid (\w,\h); \end{tikzpicture} \begin{tikzpicture}[] \draw[] (0,0) rectangle (\w,\h); \draw[orange, xstep=\w/6, ystep=0*\h/5, % Dotted Style: line width=1.0pt, dash pattern=on 0pt off \w/6, line cap=round, ] (0,0) grid (\w,\h); \end{tikzpicture} \end{document}
- How to make title visible, tcolorboxby user386618 on January 2, 2026 at 10:04 pm
I'm trying to create a hexagon frame, here what i did. \documentclass[12pt]{article} \usepackage[english, russian]{babel} \usepackage[most]{tcolorbox} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tcolorbox}[enhanced, width=\linewidth, attach boxed title to top left={xshift=5mm, yshift=-3.5mm, yshifttext=-1mm}, frame hidden, colback=white, coltitle=green, fonttitle=\large\bfseries\color{green}, boxed title style={frame hidden, colback=white}, title=Идея, underlay={ \draw[draw=green, line width=2pt, fill=green!20] (0.4,0)--(frame.west)--($(frame.north)+(frame.west)-(frame.center)+(0.4,0)$)--($(frame.north)+(frame.east)-(frame.center)-(0.4,0)$)--(frame.east)--($(frame.south)+(frame.east)-(frame.center)-(0.4,0)$)--cycle; \draw[draw=green, line width=2pt, fill=white] ($(title.south)+(title.west)-(title.center)+(0.4,0)$)--(title.west)--($(title.north)+(title.west)-(title.center)+(0.4,0)$)--($(title.north)+(title.east)-(title.center)-(0.4,0)$)--(title.east)--($(title.south)+(title.east)-(title.center)-(0.4,0)$)--cycle;}] Hexagon box Hexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon boxHexagon box \end{tcolorbox} \end{document} I'm quite fine with that, unless the title is below the figure. How to make it visible? Also i want to receive any advice from comunity how to make code from this particullar frame better
- How to tweak this tikz code with `clip`?by Explorer on January 2, 2026 at 7:17 am
I want to draw something like: \documentclass[tikz,border=5pt]{standalone} \begin{document} \begin{tikzpicture}[radius=4] % \draw[help lines] (-4,-4) grid (4,4); \begin{scope} \draw[clip] ({2*sqrt(2)},{-2*sqrt(2)}) arc [start angle=315,delta angle=90] arc [start angle=-45,delta angle=-90] arc [start angle=135,delta angle=90] arc [start angle=135,delta angle=-90] ; \fill[gray] ({4*sin(22.5)},-4) rectangle (4,4); \end{scope} \draw[dashed] ({2*sqrt(2)},{2*sqrt(2)}) arc [start angle=45,delta angle=90] ({2*sqrt(2)},{-2*sqrt(2)}) arc [start angle=-45,delta angle=-90] (0,{4-2*(4-2*sqrt(2))}) -- (0,{-(4-2*(4-2*sqrt(2)))}) ; \draw[thick] (4,0) -- (-4,0); \end{tikzpicture} \end{document} However, there are too many arcs and manually calculated coordinate and distance, I want to make good use of \clip, but it look a little bit hard than my expected, the border, is hard to control... Noted that the two code, I give, the parameter is not the same, that is not important. I want to focused on how to use clip magic to do so: what I have tried with \clip, the border is clipped in wrong... \documentclass[tikz,border=5pt]{standalone} \begin{document} \begin{tikzpicture}[radius=4] \clip circle[]; \draw[help lines] (-4,-4) grid (4,4); \draw[dashed,fill=gray] circle[]; \begin{scope} \clip (-4,-3) rectangle (4,3); \fill[white] (-4,-4) rectangle (1.5,4); \end{scope} \draw[fill=white] (0,6) circle[] (0,-6) circle[]; \end{tikzpicture} \end{document} If possible, I want to know the thought of how to design such proper drawing scheme.
- which is better to use \pgfmathsetmacro or \tikzmath to do some calculations in Tikz?by Nasser on January 1, 2026 at 10:28 pm
My goal for the new year is to learn how to add and multiply numbers in tikz. Found one can use something like this \pgfmathsetmacro{\result}{int(2000-\i*50)}; \node[labelstyle] at (dot-\i.west) {year \result}; vs \tikzmath { \result= int((2000-\i*50)); {\node[labelstyle] at (dot-\i.west) {year \result};}; } Both produce same output Since I will be doing lots of calculations, which method is the better method to use? Is there a third method to look at which can be better/easier to use? complete MWE for first method \documentclass[border=10pt]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[ dot/.style={circle, fill=black, inner sep=1.5pt}, % Style for the black dots labelstyle/.style={left, font=\small} % Style for the labels (positioned to the left) ] % Define start and end points for the vertical line \coordinate (Start) at (0, 0); \coordinate (End) at (0, 11); % Draw the vertical line \draw (Start) -- (End); % Use a foreach loop to place equally spaced dots and labels \foreach \i in {0, 1, ..., 11} { % Place the dot as a node on the line \node[dot] (dot-\i) at (0, \i) {}; % Place the label to the left of the dot % The "left" anchor ensures the label sits to the left of the dot node \pgfmathsetmacro{\result}{int(2000-\i*50)}; \node[labelstyle] at (dot-\i.west) {year \result}; } \end{tikzpicture} \end{document} Complete MWE for the second method \documentclass[border=10pt]{standalone} \usepackage{tikz} \usetikzlibrary{math} \begin{document} \begin{tikzpicture}[ dot/.style={circle, fill=black, inner sep=1.5pt}, % Style for the black dots labelstyle/.style={left, font=\small} % Style for the labels (positioned to the left) ] % Define start and end points for the vertical line \coordinate (Start) at (0, 0); \coordinate (End) at (0, 11); % Draw the vertical line \draw (Start) -- (End); % Use a foreach loop to place equally spaced dots and labels \foreach \i in {0, 1, ..., 11} { % Place the dot as a node on the line \node[dot] (dot-\i) at (0, \i) {}; % Place the label to the left of the dot % The "left" anchor ensures the label sits to the left of the dot node \tikzmath { \result= int((2000-\i*50)); {\node[labelstyle] at (dot-\i.west) {year \result};}; } } \end{tikzpicture} \end{document} TL 2025
- a square with watercolor-like fill and a hand-drawn appearanceby Irreversible on January 1, 2026 at 12:53 pm
I want to draw a square in LaTeX where the inside has a watercolor-like fill and a hand-drawn appearance. Is it possible to draw this with LaTeX?
- Pic or Shape for collection of ready to use objects?by Sammy on December 31, 2025 at 2:25 pm
For the graphics I use on my physics exercise sheets made with TikZ I often use the same objects (hooks, masses, carts, pulleys, force gauges,...). So instead of copy-pasting and modifying the code of these objects I think it makes sense to make them into a ready to use object. There are three ways I know of to make that happen: TeX macros, pics and shapes. There are some features I wish the implementation of these objects to have and need some advice on how to implement it in order to have those features: An object should have multiple anchors so I can easily use certain points for further construction and choose which anchor to use for the placement (so there is no need to calculate that stuff manually). The hook for example could be placed at it's base or the actual hook and either one should be available afterwards for further placement of objects or paths. A default style should be set, i.e. the fill color or shading of the mass body, that can be overwritten. If placed inside a scope that changes shift, rotation, scale, line width,... these changes should automatically also apply to the object as a whole. I want to be able to construct new objects from already existing objects, i.e. I want to be able to use the hook as part of the mass, force gauge and cart. Right now I'm leaning towards defining new shapes, even tho I haven't used low level pgf before. As far as I can see 1 and 3 are no problem with shapes. I feel like 2 could also be achieved (any hints are appreciated - maybe defining a new style that uses that shape?). I however have no Idea if or how to make 4 work in defining a new shape. Pics on the other hand would make 2 and 4 easy as far as I can imagine. But they don't respond to the settings of a scope (3). Also anchors (1) are not natively supported but using tikzmark one answer to this question Anchoring TiKZ pics suggests this could be achieved as well (although I imagine it to be not quite as powerful as a new shape and takes two compilation runs if I understood correctly). Any thoughts, hints or pieces of advice are very welcome. I hope I described the setting clear enough. Edit The following Example is not meant to be beautiful but hopefully helps to illustrate the issue: \documentclass[tikz]{standalone} \usetikzlibrary{calc} \usetikzlibrary{tikzmark} \begin{document} \tikzset{ hook/.pic={ \draw[double=gray!80, double distance=1.4pt] (0,0) .. controls (0,-1.5) and (0,{1/sin(45)-2.5}) .. ($(45:1)+(0,-2.5)$) arc(405:140:1); \node[inner sep=2mm] (-hole) at (0,-2.5) {}; } } \tikzset{ cart/.pic={ \shadedraw[left color=blue, right color=blue!50] (-3,0) rectangle (3,2); \shadedraw[left color=black, right color=gray] (2,-.8) circle (.8); \shadedraw[left color=black, right color=gray] (-2,-.8) circle (.8); \pic[transform shape,rotate=90,scale=.5] (h) at (3,1) {hook}; \coordinate (-front-wheel) at (2,-1.6); \coordinate (-back-wheel) at (-2,-1.6); \node[inner sep=2mm] (-hook) at (h-hole) {}; } } \begin{tikzpicture} \draw (0,0) -- (8,0) -- (8,2); \pic[pic anchor=(-back-wheel),scale=.5] (cart) at (.5,0) {cart}; \pic[rotate=270,xscale=-1,scale=.25] (hook) at (8,0|-cart-hook) {hook}; \draw[ultra thick, line cap=round] (cart-hook) -- (hook-hole); \end{tikzpicture} \end{document} So using a pic with tikzmark (and transform shape as I've discovered) seems to check all the requirements. Can this also be achieved with a custom shape? As in this solution I dislike a few things: tikzmark needs two compilation runs no border anchors can be defined (at least I don't know how) It seems to me all anchors are defined every time a pic is inserted and not calculated when needed as with shapes. I'm not sure about the impacts on compilation time.
- Could you add "Happy New Year" in your language? Have a wonderful 2026! [closed]by Ñupi on December 31, 2025 at 3:11 am
\documentclass[aspectratio=169]{beamer} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{tikz} \usetikzlibrary{shapes.geometric, shadings, shadows} \setbeamertemplate{navigation symbols}{} \begin{document} \begin{frame}[plain] \begin{tikzpicture}[remember picture, overlay] \fill[top color=blue!20!black, bottom color=black] (current page.south west) rectangle (current page.north east); \foreach \i in {1,...,60} { \fill[white, opacity=0.4] (current page.center) ++({rand*8}, {rand*4.5}) circle (0.03); } \node[white, opacity=0.75, font=\small\itshape] at (-5, 2.5) {Happy New Year}; % \node[white, opacity=0.75, font=\small\itshape] at (5, -2.5) {Bonne Année}; \node[align=center, text=white] at (current page.center) { {\fontsize{35}{40}\selectfont \textbf{\textcolor{yellow!70!white}{¡Happy New Year!}}} \\[0.3cm] {\fontsize{20}{24}\selectfont \textit{and prosperous}} \\[0.5cm] {\fontsize{75}{75}\selectfont \textbf{\textcolor{white}{2026}}} \\[0.8cm] {\fontsize{18}{22}\selectfont \textsf{\textbf{Friends of \LaTeX}}} }; \draw[very thick, orange!60!yellow, opacity=0.6] (-4,-1.8) -- (4,-1.8); \shade[ball color=yellow, opacity=0.3] (-7, 3) circle (0.5); \shade[ball color=orange, opacity=0.2] (7, -3) circle (0.8); \end{tikzpicture} \end{frame} \end{document}
- Drawing Only a Portion of an Oval Frameby DDS on December 30, 2025 at 10:39 pm
Consider the following code which I compile with xelatex: \documentclass{book} \usepackage{graphicx} \usepackage[abs]{overpic} \usepackage{tikz} \definecolor{cadmiumgreen}{rgb}{0.0, 0.42, 0.235} % 0, 107, 60 \definecolor{Gold}{RGB}{228,168,73} \begin{document} \thispagestyle{empty} \begin{center} \begin{tikzpicture} \clip (0,0) ellipse (4.25cm and 5.5cm); \draw[line width=5pt,Gold,fill=cadmiumgreen] ellipse (4.25cm and 5.5cm); \node at (0,0) {\includegraphics[scale=.37,clip, trim = 0 0 0 0]{example-image-a}}; \draw[line width=12pt,Gold!70!black] ellipse (4.25cm and 5.5cm); \end{tikzpicture} \end{center} \end{document} with the output: QUESTION: How may I draw only a part of the 12pt-thick oval frame; in particular, relative to the node (0,0), draw the frame from only -45 degrees to 225 degrees in a clockwise fashion (instead of from -90 degrees to 270 degrees which gives the entire oval)? Thank you.
- circuitikz: How to use circuitikz inside a TikZ-matrixby cis on December 30, 2025 at 11:27 am
Is it possible to use circuitikz-shapes as cells inside a TikZ-matrix? (I mean, as cells <*> & <*> & <*> ... \\, how to place nodes afterwards is already clear.) If I put in |[tgenericshape]|{} I get an error ! Package PGF Math Error: Unknown function base (in 'base'). \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage{circuitikz} \usetikzlibrary{matrix} \begin{document} \begin{circuitikz}[] \node[tgenericshape, label=center:GS0](G0){}; \matrix[matrix of nodes, nodes in empty cells, draw, column sep=11mm, ] at (0,-2) (m){ 1 & 2 & 3 \\ %|[tgenericshape, label=center:GS1]|{} & |[fill=pink]|{Test} & \\ does not work }; \end{circuitikz} \end{document}
- circuitikz: How to read out the value of bipoles/lengthby cis on December 30, 2025 at 8:55 am
According to the manual, section 3.1.4.1 "Components size", bipoles/length (default 1.4cm) is the central parameter; "which can be interpreted as the length of a resistor (including reasonable connections): all other lengths are relative to this value." How can I read out bipoles/length? I tried \pgfmathsetlengthmacro\Rlength{ %\ctikzvalueof{bipoles/length}% does not work %\pgfkeysvalueof{/tikz/circuitikz/bipoles/length}% does not work 5mm% works } without success. What do I have to do? \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage{circuitikz} \begin{document} \pgfmathsetlengthmacro\Rlength{ %\ctikzvalueof{bipoles/length}% does not work %\pgfkeysvalueof{/tikz/circuitikz/bipoles/length}% does not work 5mm% works } \begin{circuitikz}[european resistors] \draw[] (0,0) to[R, name=R0] (2,0); \draw[red] (R0.west) -- +(\Rlength,0) node[below=3mm]{\Rlength}; \end{circuitikz} \ctikzset{bipoles/length=22.5mm,}% test for value change \begin{circuitikz}[european resistors] \draw[] (0,0) to[R, name=R0] (2,0); \draw[red] (R0.west) -- +(\Rlength,0) node[below=3mm]{\Rlength}; \end{circuitikz} \end{document}
- How can I place a mercator map on an overlay tikzpicture?by TobiBS on December 29, 2025 at 9:54 pm
I want to precisely place a mercatormap on my page and hence use the remember picture,overlay options. But I find no way to e.g. put the top left corner of my map to the center of the page. Here is my MWE: \def\mrcpkgprefix{} \documentclass{scrartcl} \usepackage{mercatormap} \begin{document} \begin{tikzpicture}[remember picture, overlay] \node at (current page.center) {E.g. left Corner of the map here?}; \mrcdefinemap{west=9.1,east=9.45,south=48.7,north=48.95,tile size=1cm,zoom=14} \path[draw,fill=green!10] (mrcmap.south west) rectangle (mrcmap.north east); \mrcdrawnetwork \coordinate (Stuttgart) at (mrcq cs:48.775556:9.182778); \node at (Stuttgart) {Stuttgart}; \end{tikzpicture} \end{document} Any idea which option or trick can help to do what I want to achieve?
- circuitikz: European Amplifier (en amp) without pins or with absolut valued pin lengthby cis on December 29, 2025 at 12:10 pm
I want to create an en amp with a pin length of 0 - alternatively: a pin length with a clearly defined value, for example 5mm. I tried to transfer the "trick" \ctikzset{tripoles/en amp/port width=1, tripoles/en amp/width=1.19, % = 1.7*0.7 } from 4.20.2.2 "Input and output pins symbols"; but this only works with op amp. What do I have to do? \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage{circuitikz} \begin{document} \begin{circuitikz}[] \ctikzset{tripoles/en amp/port width=1, tripoles/en amp/width=1.19, % = 1.7*0.7 } \node[en amp, en amp text={No pins}, label={[yshift=-12mm]below:works not} ] (A){please!}; %% --> Trick from 4.20.2.2 "Input and output pins symbols" \ctikzset{tripoles/op amp/port width=1, tripoles/op amp/width=1.19, % 1.7*0.7 } \draw (3,0) node[op amp, color=blue, label={[yshift=-12mm]below:works} ]{}; \end{circuitikz} \end{document}
- DNA helix and chromosome symbols built in tikz-pgfby Sebastiano on December 27, 2025 at 10:22 pm
I'm wondering if there are predefined symbols chromosomes-dna in pdfLaTeX or done in TikZ similar to those used in biology textbooks. Here two examples: What libraries can I use to create the envelope curves in blue for the "X"? (For the 2-nd figure, credit from wikipedia https://en.wikipedia.org/wiki/Chromosome#/media/File:Chromosome.svg)
- I would like to discretize the "tiles" into rectangular prismatic groups, sort each group, then sort the groups by each other or be shown a better wayby Jasper on December 4, 2025 at 7:58 am
I have built a comparator which can determine the occlusive relationship between two 0--2-dimensioal affine tiles (using their simplicial representations). In English, if I have two tiles (a tile is a point, line segment, or triangle), I can determining which one occludes the other, or if there is no occlusion (the inconclusive case). Currently, this requires an extremely expensive SCC topological sort (quadratic based on the number of tiles). I have the idea that I would like to speed this up, and I have a proposal for doing so (though, I am all ears to alternative ideas too). Basically, my idea is to partition the scene into rectangular prismatic regions (possibly with some overlap), sorting each one individually. Then, each rectangular prismatic region could use a waaay simpler sorting method on the set of rectangular prismatic region, once their constituent parts are sorted. This is my AI generated SCC topological sort routine, which has been working for ages. I am confident in it, based on it having not failed yet. How could I go about implementing this without visual artefacts from tiles which cross the boundary of two or more prisms? Alternatively, what better methods might I consider which I haven't yet? -- occlusion graph + SCC topo sort (bboxes computed on Cartesian coords) local n = #items local bboxes, graph = {}, {} for i = 1, n do bboxes[i] = { get_bbox2(items[i]) }; graph[i] = {} end for i = 1, n - 1 do for j = i + 1, n do if bboxes_overlap2(bboxes[i], bboxes[j]) then local r = cmp(items[i], items[j]) if r == true then table.insert(graph[i], j) elseif r == false then table.insert(graph[j], i) end end end end local index, stack, indices, lowlink, onstack, sccs = 0, {}, {}, {}, {}, {} for i = 1, n do indices[i], lowlink[i] = -1, -1 end local function dfs(v) indices[v], lowlink[v] = index, index; index = index + 1 stack[#stack+1] = v; onstack[v] = true for _, w in ipairs(graph[v]) do if indices[w] == -1 then dfs(w); lowlink[v] = math.min(lowlink[v], lowlink[w]) elseif onstack[w] then lowlink[v] = math.min(lowlink[v], indices[w]) end end if lowlink[v] == indices[v] then local scc = {} while true do local w = table.remove(stack); onstack[w] = false scc[#scc+1] = w if w == v then break end end sccs[#sccs+1] = scc end end for v = 1, n do if indices[v] == -1 then dfs(v) end end local scc_index, scc_graph, indeg = {}, {}, {} for i, comp in ipairs(sccs) do for _, v in ipairs(comp) do scc_index[v] = i end scc_graph[i], indeg[i] = {}, 0 end for v = 1, n do for _, w in ipairs(graph[v]) do local si, sj = scc_index[v], scc_index[w] if si ~= sj then table.insert(scc_graph[si], sj); indeg[sj] = indeg[sj] + 1 end end end local queue, sorted = {}, {} for i = 1, #sccs do if indeg[i] == 0 then queue[#queue+1] = i end end while #queue > 0 do local i = table.remove(queue, 1) for _, v in ipairs(sccs[i]) do sorted[#sorted+1] = items[v] end for _, j in ipairs(scc_graph[i]) do indeg[j] = indeg[j] - 1 if indeg[j] == 0 then queue[#queue+1] = j end end end In fact, I would also like to employ a similar strategy for partitioning, since it is also quadratic, but I think that if I saw it for occlusion, that it would be simple to re-implement for partitioning. This MWE, for example, takes ages to compile, and I believe it should be speed-up-able. This version is currently on TeXLive and MikTeX (and on CTAN), so there is no need to use the GitHub version. \documentclass[tikz,border=1cm]{standalone} \usepackage{lua-tikz3dtools} % https://github.com/Pseudonym321/TikZ-Animations/tree/master1/TikZ/lua-tikz3dtools \begin{document} \begin{luatikztdtoolspicture}[ C1 = { {{-3,-3,0,1}} } ,C2 = { {{3,3,-10,1}} } ,light = { {{0,0,-2,1}} } ] \pgfmathsetmacro{\param}{0} \setobject[ name = {T} ,object = { matrix_multiply( matrix_multiply( euler(pi/2,pi/4+pi/4*sin(\param),5.25*pi/6+\param) ,translate(0,0,-5) ) ,matrix_multiply( { {1,0,0,0} ,{0,1,0,0} ,{0,0,1,0} ,{0,0,0,1} } ,matrix_multiply(xscale(1/2),yscale(1/2)) ) ) } ] \setobject[ name = {I} ,object = { matrix_inverse(T) } ] \appendsurface[ ustart = {-2} ,ustop = {2} ,usamples = {20} ,vstart = {-2} ,vstop = {2} ,vsamples = {20} ,transformation = {T} ,x = {u} ,y = {v} ,z = {u^4 + v^4 - 4*u*v + 1} ,fill options = { preaction = { fill = green ,fill opacity = 0.2 } ,postaction = { draw = blue ,ultra thin ,line join = round } } ,filter = { abs(matrix_multiply(A,I)[1][3])<2.01 and abs(matrix_multiply(B,I)[1][3])<2.01 and abs(matrix_multiply(C,I)[1][3])<2.01 and abs(matrix_multiply(A,I)[1][2])<2.01 and abs(matrix_multiply(B,I)[1][2])<2.01 and abs(matrix_multiply(C,I)[1][2])<2.01 and abs(matrix_multiply(A,I)[1][1])<2.01 and abs(matrix_multiply(B,I)[1][1])<2.01 and abs(matrix_multiply(C,I)[1][1])<2.01 } ] \appendsolid[ ustart = {-2} ,ustop = {2} ,usamples = {2} ,vstart = {-2} ,vstop = {2} ,vsamples = {2} ,wstart = {-2} ,wstop = {2} ,wsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {w} ,fill options = { preaction = { fill = none ,fill opacity = 0.5 } ,postaction = { draw = none ,ultra thin ,line join = round ,line cap = round } } ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {0} ,y = {0} ,z = {u} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {0} ,y = {0} ,z = {4.3} ,transformation = {T} ,name = {\(z\)} ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {0} ,y = {u} ,z = {0} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {0} ,y = {4.3} ,z = {0} ,transformation = {T} ,name = {\(y\)} ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {u} ,y = {0} ,z = {0} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {4.3} ,y = {0} ,z = {0} ,transformation = {T} ,name = {\(x\)} ] \foreach \p in {-4,-3,...,4} { \appendcurve[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,x = {u} ,y = {\p} ,z = {0} ,transformation = {T} ,draw options = { draw = black!70!white ,ultra thin ,line cap = round ,densely dashed } ] \appendcurve[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,x = {\p} ,y = {u} ,z = {0} ,transformation = {T} ,draw options = { draw = black!90!white ,ultra thin ,line cap = round ,densely dashed } ] } \appendsurface[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,vstart = {-4} ,vstop = {4} ,vsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {0} ,fill options = { preaction = { fill = gray!70!white ,fill opacity = 0.6 } ,postaction = { draw = none ,ultra thin ,line join = round } } ] \end{luatikztdtoolspicture} \end{document}
- tikz node fill to highlight text causes extra line below text (used in tblr)by bennynihon on November 29, 2025 at 5:58 am
When I use the text highlighting tikz command, as shared here, it adds an extra line or vertical spacing below it. In my case I'm using it in a two column nested tblr. You can see if the tikz highlight is replaced with a simple bold text, it works as expected with no extra vertical space. I thought it was the size of the highlight creating the issue, so I tried an 'inner sep=1pt' in the tikz command, but it still results in the extra space. How can I avoid this extra space below? Thank you. \documentclass{article} \usepackage{tabularray} \usepackage{tikz} \definecolor{mblue}{HTML}{2a66ad} \newcommand{\hlitet}[2][mblue]{% \hspace{0pt}{% \tikz[baseline=(N.base)]\node[fill=#1,rounded corners](N){#2}; }% \hspace{-2pt}% } % using hlines and vlines to show the effect \NewDocumentCommand{\fsmtx}{mm}{% \begin{tblr}{colspec={@{}X[l,-1]@{\hspace{4pt}}X[l]@{}},baseline={T},hlines,vlines}% {\hlitet[mblue]{\textcolor{white}{#1}}} & {#2}% \end{tblr}% } \NewDocumentCommand{\fsmtxb}{mm}{% \begin{tblr}{colspec={@{}X[l,-1]@{\hspace{4pt}}X[l]@{}},baseline={T},hlines,vlines}% {\textcolor{mblue}{\textbf{#1.}}} & {#2}% \end{tblr}% } \begin{document} \begin{longtblr}{ colspec={X[l,-1]X[l,-1]}, rowhead=1, hlines,vlines } {State} & {Transitions} \\ {StateA} & \fsmtx{a}{this is a test of a single line description} \fsmtx{b}{this is a test of a multi line description, as this will occupy a second line} \\ {StateB} & \fsmtxb{a}{this is a test of a single line description} \fsmtxb{b}{this is a test of a multi line description, as this will occupy a second line} \end{longtblr} \end{document} Update: swapping the \hlitet with this tcbox solution below, seems to work well. But I am curious as to why the tikz solution causes the additional vertical spacing. \newcommand\hliteb[2][mblue]{\tcbox[on line, colback=#1, colframe=#1, boxsep=0pt, top=3pt, bottom=3pt, left=3pt, right=3pt, boxrule=0pt]{#2}}
- Adding a colormap to a solution curve of a vector fieldby Black Mild on October 7, 2025 at 8:29 pm
Here the curve is drawn with a single color (red) It's easy to get the solution curve. The below figure is drawn in this app for y'=x^2+y^2-1, y(0)=1/2. As you can notice the color of the curve is varying from red (x<-1) to purple (-1<x<1) then to blue (x>1). It is not color set of the rainbow, so it is not synchronious to the Rainbow colormap. My question: How to add a given colormap (such as Rainbow) to a solution curve of a vector field? I guess this is a kind of popular, but can not find a way with Asymptote. I expect not only Asymptote code but also any others as TikZ, MetaPost, lua, etc. The code should be apply for any colormaps Please use my code here as MWE. Update: another MWE with AI and my poor Python import numpy as np import matplotlib.pyplot as plt from matplotlib.collections import LineCollection from matplotlib.colors import Normalize from scipy.integrate import solve_ivp # ============================================================ # 1. Configuration # ============================================================ x_min, x_max = -3, 3 y_min, y_max = -3, 3 density = 8 # Number of initial conditions per axis def ode_func(t, y): """ ODE: y' = x^2 + y^2 - 1 Here, t plays the role of x. """ return t**2 + y[0]**2 - 1 def exit_box(t, y): """ Event function: stop integration when the solution leaves the box |x| <= 3, |y| <= 3. """ return max(abs(t), abs(y[0])) - 3 exit_box.terminal = True # ============================================================ # 2. Figure setup # ============================================================ fig, ax = plt.subplots(figsize=(8, 8)) # Initial conditions x_inits = np.linspace(x_min, x_max, density) y_inits = np.linspace(y_min, y_max, density) manual_starts = [ (-2.7, 0), (-2.7, 1), (-2.7, 2), ( 2.7, 0), ( 2.7,-1), ( 2.7,-2), (-0.75, 2), (0.75, -2), (-1, 0), (1, 0) ] starts = [(x0, y0) for x0 in x_inits for y0 in y_inits] starts += manual_starts all_segments = [] all_values = [] print("Computing solution curves...") # ============================================================ # 3. Solve ODEs and collect line segments # ============================================================ for x0, y0 in starts: for direction in [1, -1]: t_span = [x0, direction * 3.2] sol = solve_ivp( ode_func, t_span, [y0], events=exit_box, max_step=0.05 ) x = sol.t y = sol.y[0] if len(x) > 1: points = np.array([x, y]).T.reshape(-1, 1, 2) segments = np.concatenate([points[:-1], points[1:]], axis=1) all_segments.extend(segments) slopes = x[:-1]**2 + y[:-1]**2 - 1 all_values.extend(slopes) all_values = np.array(all_values) # ============================================================ # 4. Background vector field (normalized) # ============================================================ X, Y = np.meshgrid( np.linspace(x_min, x_max, 20), np.linspace(y_min, y_max, 20) ) U = np.ones_like(X) V = X**2 + Y**2 - 1 N = np.sqrt(U**2 + V**2) ax.quiver( X, Y, U / N, V / N, color="gray", alpha=0.3, pivot="mid" ) # ============================================================ # 5. LineCollection with true rainbow colormap # ============================================================ norm = Normalize( vmin=np.percentile(all_values, 5), vmax=np.percentile(all_values, 95) ) lc = LineCollection( all_segments, cmap="rainbow", norm=norm, linewidth=1.5, alpha=0.85 ) lc.set_array(all_values) ax.add_collection(lc) # ============================================================ # 6. Axes styling and annotations # ============================================================ ax.set_xlim(x_min, x_max) ax.set_ylim(y_min, y_max) ax.set_aspect("equal", adjustable="box") ax.set_xlabel("x") ax.set_ylabel("y") ax.set_title(r"Solution curves for $y' = x^2 + y^2 - 1$") cbar = plt.colorbar(lc, ax=ax) cbar.set_label(r"Slope value $y' = x^2 + y^2 - 1$") ax.grid(True, linestyle=":", alpha=0.6) plt.tight_layout() plt.savefig("solution_curves_rainbow.png", dpi=200) plt.show()
- Rotate ellipsoid in Tikz environmentby Debora on September 2, 2022 at 8:58 am
This is the result of my code: Now, I would like to have the inner ellipsoid aligned with the x-axis, and not with the y-axis as it is. In other words, I would like to rotate the all ellipsoid in the xy-plane by 90 degrees, so I should introduce some prospective somehow, like this (in black where I want to place the ellipsoid): How should I modify my code? (Simplified code without axis and lines, but that's not important) \begin{tikzpicture}[scale = 0.3][line cap=round, line join=round] \draw [ball color=white,very thin,opacity=0.4] (0,0,0) circle (8) ; \fill[white,opacity=0.6] (0,0) circle (8 and 3); \shade[right color=orange,middle color=red,left color=blue,opacity=0.4,shading angle=-110] (0,0) circle (8 and 3); \shade[ball color=orange,opacity=0.3] (0,0) circle (8 and 3); \draw[line width=0.5pt,rotate around={0.:(0.,0.)},dash pattern=on 4pt off 3pt, color = violet, opacity = 0.6] (0,0) ellipse (1 and 3); \end{tikzpicture}
- Converting an SVG image to TikZ codeby Hendrra on May 21, 2017 at 8:26 am
I am to convert an SVG image to TikZ code. I have never done that before thus I have a few questions. First of all do I need Inkscape or any other program like this? Maybe there is a method using just Python? Have you ever done that before? Are there any typical errors or problems?
- Circular Motionby oo2t on October 2, 2016 at 2:27 pm
I'm trying to draw three vectors that are tangent to the circle, as shown below. Is it possible to use \foreach to duplicate one vector around the circle? If so, can someone help me to draw this picture?