TikZ
- Aligning labels in multi-panel figuresby NicolasBourbaki on June 16, 2026 at 2:11 pm
I would like to create a multi-panel figure with two subpanels of different width and height. The labels should be placed in the upper left corner of each subpanel with the left margin of the labels aligned to the left margin of the graphic in the corresponding subpanel (and baseline of the letters on the same height just on top ("north") of the highest graphic of the subpanels: My approach in TikZ does not exactly align the left margin of the labels to the left margin in the corresponding subpanel: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} % the files green_ellipse and blue_square are on my disk; any graphics file would do \node[anchor=east, inner sep=0pt] at (0,0){\includegraphics[width=.3\textwidth]{green_ellipse}}; \node[anchor=south east] at (-3.7,1.8) {a}; \node[anchor=west,inner sep=0pt] at (1,0){\includegraphics[width=.6\textwidth]{blue_square}}; \node[anchor=south east] at (1,1.8) {b}; \end{tikzpicture} \end{document} How could the left margins of the labels with the left margins of the graphics in the subpanels and the baseline of the letters just on top ("north") of the highest graphic of the subpanels.
- TikZ move scope to bottom left of a figureby Thomas on June 16, 2026 at 7:42 am
I have a figure to which I add representation of axis. Using scope environment I'm able to scale and move it where I want on the figure. Would it be possible to make it always at a specific position in the figure (for instance bottom left), so if I change the content of the figure by adding other element, the scope would still be placed where I intended. For a node I would use anchor. Here is a MWE: \documentclass{article} \usepackage{tikz} \usetikzlibrary{backgrounds} \begin{document} \begin{tikzpicture}[show background rectangle] \draw[red,fill=yellow] (0,0,0) -- ++(-2,0,0) -- ++(0,-1,0) -- ++(2,0,0) -- cycle; \draw[red,fill=yellow] (0,0,0) -- ++(0,0,-1) -- ++(0,-1,0) -- ++(0,0,1) -- cycle; \draw[red,fill=yellow] (0,0,0) -- ++(-2,0,0) -- ++(0,0,-1) -- ++(2,0,0) -- cycle; \begin{scope}[xshift=-3cm, yshift=-0.56cm, scale=0.4] \draw[->, red] (0,0) -- (0,1) node[anchor=north east] {$x$}; \draw[->, green] (0,0) -- (-1,0) node[anchor=north west] {$y$}; \draw[blue] (0,0) node {$\odot$}; \draw[blue] (0,0) node[anchor=north west] {$z$}; \end{scope} \end{tikzpicture} \end{document} I manually set the xshift and yshift so the arrows are on the bottom part of the figure. (Note: here the scope does enlarge the figure on the left because there is nothing, but in my case where I'm facing this issue, there are other object on the top left part of it)
- How to design station signs for Taiwan Railway in TeX?by mathrm alpha on June 16, 2026 at 4:08 am
Although I wrote a LaTeX-like design for Taiwanese train station signs, the resemblance is still somewhat lacking. https://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/ROC_Taiwan_Railways_Administration_Logo.svg/960px-ROC_Taiwan_Railways_Administration_Logo.svg.png \documentclass{article} \usepackage{xeCJK,amssymb} \usepackage[ paperwidth=5in, paperheight=3in, margin=0.2in ]{geometry} \usepackage{graphicx} \usepackage{tikz} \pagestyle{empty} \begin{document} \begin{tikzpicture}[remember picture,overlay] \node[anchor=north west, xshift=0in, yshift=0in] at (current page.north west) { \includegraphics[width=0.5in,height=0.5in]{960px-ROC_Taiwan_Railways_Administration_Logo.svg.png} }; \end{tikzpicture} \begin{tikzpicture}[remember picture,overlay] \node[align=center, text=black, yshift=0.25in] at (current page.center) { {\fontsize{28pt}{34pt}\selectfont Miaoli} \\[0.2em] {\fontsize{32pt}{38pt}\selectfont 苗栗} }; \end{tikzpicture} \begin{tikzpicture}[remember picture,overlay] \node[ draw, line width=0.8pt, minimum size=0.9in, inner sep=0pt, align=center, font=\fontsize{12pt}{12pt}\selectfont ] at ([xshift=1.25in, yshift=0.25in]current page.center) { 苗栗縣\\ 苗栗市 }; \end{tikzpicture} \begin{tikzpicture}[remember picture,overlay] \node[anchor=south west, xshift=0.2in, yshift=0.2in] at (current page.south west) { {\Large 豐富 Fengfu} }; \node[anchor=south east, xshift=-0.2in, yshift=0.2in] at (current page.south east) { {\Large 南勢 Nanshi} }; \end{tikzpicture} \begin{tikzpicture}[remember picture,overlay] \draw[green!60!black, line width=1.2pt] ([yshift=0.65in]current page.south west) -- ([yshift=0.65in]current page.south east); \node[anchor=west, text=green!60!black] at ([yshift=0.78in]current page.south west) {\large $\blacktriangleleft$ 3.9 公里 (km)}; \node[anchor=east, text=green!60!black] at ([yshift=0.78in]current page.south east) {\large 6.6 公里 (km) $\blacktriangleright$}; \end{tikzpicture} \end{document} A better version should be: Source: http://trstour.com/miao-li.htm
- Print service tells me the gradient I created with TikZ is longer than the Earth's circumferenceby flyx on June 15, 2026 at 8:08 am
I am designing playing cards, and I use a print service (https://meinspiel.de if that's relevant). I create my cards with a heading styled with tikz, like so: \documentclass{article} \usepackage[paperwidth=65mm,paperheight=97mm, margin=7mm]{geometry} \pagestyle{empty} \RequirePackage[x-4]{pdfx} \setCMYKcolorprofile{coated_FOGRA39L_argl.icc} {Coated FOGRA39} {FOGRA39 (ISO Coated v2 300\% (ECI))} {http://www.argyllcms.com/} \usepackage[overprint]{colorspace} \RequirePackage{tikz} \usetikzlibrary{positioning,shapes,calc,backgrounds} \definecolor{blue1}{cmyk}{0.6818,0.3939,0,0.7412} \definecolor{blue2}{cmyk}{0.6339,0.2768,0,0.5608} \tikzset{ pics/heading/.style={code={ \node[anchor=north west] (heading) at ($(current page.north west) + (7, -7)$) {\textoverprint[0]{\textcolor{white}{\textsf{#1}}}}; \begin{scope}[on background layer] \fill[top color=blue1, bottom color=blue2] (current page.north west) -- (heading.south west-|current page.north west) -- (heading.south east) .. controls +(right:5) and +(left:5) .. +(10, 2) -| (current page.north east) -- cycle; \end{scope} }} } \begin{document} \begin{tikzpicture}[x=1mm, y=1mm, remember picture, overlay] \pic {heading={My Heading}}; \end{tikzpicture} \end{document} As you can see, I set the card's dimensions, specify PDF/X-4 output and the ISO Coated v2 300% (ECI) color profile just like the print service requires. Then I enable overprint (unsure whether this is relevant for my issue) for black text (but the heading is white, so I disable it there again). I define a tikz pic to use for drawing the heading of each card. Finally, I create a document with a single card that uses that pic as heading. The result looks like this: I gave that to the printing service, and they printed the heading as two areas split horizontally with different colors, instead of the gradient. When I asked them what the problem is, they answered this (translated from German): The data is set up in a strange way. The gradient consists of two parts, which lead to it being cut back during conversion. Also, the size of the gradient is extremely huge. I don't exaggerate. It has a width of 352777777777,425mm, i.e. 352.777,78km! While we do have meter scale from time to time, I've never seen kilometers. (The circumference of Earth at the equator is about 40.075 km to put that into context.) It may be that this is why there was an error during conversion. We suggest to embed the gradient as picture to avoid such errors. Also, when gradients are pictures, the print is cleaner and smoother. So, I guess my question is: How do I create the gradient so that the print service is happy? I don't feel like I have enough control over whatever tikz does here.
- Cover page in LaTeXby Jos on June 14, 2026 at 7:38 pm
How can I get this cover page using LaTeX? I have tried using this code, but I can´t get it. This is a cover page that I want for my dissertation. \documentclass{article} \usepackage{tikz} \usepackage{graphicx} \begin{document} \begin{titlepage} \begin{tikzpicture}[remember picture, overlay] % Your logo \node[anchor=north west] at (1.5in,-1.0625in) {% \includegraphics[width=1in,height=1.0625in]{example-image-duck} }; % Line 1: arriba (horizontal) \draw[line width=2pt] (3in, -1.5in) -- (7in, -1.5in); % Line 2: abajo (horizontal, más cerca) \draw[line width=1pt] (3in, -1.8in) -- (7in, -1.8in); % ===== TRES LÍNEAS VERTICALES ===== % La imagen termina en: -1.0625in - 1.0625in = -2.125in % Línea vertical 1 (desde abajo de la imagen hacia abajo) \draw[line width=1pt] (1.9in, -2.5in) -- (1.9in, -8in); % Línea vertical 2 (centro, espaciada 0.5in) \draw[line width=2pt] (2.1in, -2.5in) -- (2.1in, -8in); % Línea vertical 3 (derecha, espaciada 0.5in) \draw[line width=1pt] (2.3in, -2.5in) -- (2.3in, -8in); \end{tikzpicture} \begin{tikzpicture}[remember picture, overlay] \node[anchor=south west] at (1.5in,-8.8125 in) {% \includegraphics[width=1in,height=1.0625in]{example-image-duck} }; \end{tikzpicture} \end{titlepage} \end{document}
- Symbol of cannonby Sebastiano on June 14, 2026 at 12:15 pm
I want to reproduce a cannon considering in old style (one of these) considering that I have not seen a specific symbol. Does anyone know if there’s a symbol that resembles one of this image? I have not found anything.
- TikZ snail's 🐌 outline rotation text layoutby mathrm alpha on June 14, 2026 at 2:31 am
Although this was mentioned last time: TeX chinese image poetry image text layout However, it seems no one has mentioned the layout of the snail's rotating circle text in the TeX code. Source: https://jedi.nehs.hc.edu.tw/newsletter/306/poem.html I wrote a LaTeX program that rotates text, but the result isn't quite like this image; it's just a reference to the circle rotation text format. Furthermore, the "比羚羊還要快。" part is missing display. \documentclass{article} \usepackage{tikz,xeCJK} \usepackage[margin=0.5in]{geometry} \setCJKmainfont{Noto Sans CJK TC} \usetikzlibrary{decorations.text} \begin{document} \centering \begin{tikzpicture} % Define colors based on the image \definecolor{snailbody}{RGB}{240, 200, 180} \definecolor{shellbase}{RGB}{220, 170, 150} % Body and Tail \fill[snailbody] (-3.5, 0.5) .. controls (-4, -1) and (-3.5, -3.5) .. (0, -3.5) -- (6, -2.5) -- (0, -2.8) .. controls (-2, -2.8) and (-3, -1) .. (-3.5, 0.5); % Head \fill[snailbody] (-3.5, 0.5) circle (0.9); % Antennae \draw[snailbody, line width=4pt] (-3.9, 1.2) -- (-4.3, 2.6); \fill[snailbody] (-4.3, 2.7) circle (0.2); \draw[snailbody, line width=4pt] (-3.1, 1.2) -- (-2.9, 2.6); \fill[snailbody] (-2.9, 2.7) circle (0.2); % Shell (large circle) \fill[shellbase] (0.5, 0) circle (3.7); %text parts \path [ decorate, decoration={ text along path, text={背著重重的家,上山下海,尋找食物,我總比別人慢一步,我想如果我拋棄沉重的家,我一定爬得比羚羊還要快。}, text align=center } ] (0.5, 0) ++(180:4.0) arc (180:0:4.0); \end{tikzpicture} \end{document} Although there are similar: How to fine tune rotation of text along circular path? However, There was no mention of a text rotation format resembling a snail's outline.
- Coil decoration on curved path looks strangeby nogrodrigo on June 13, 2026 at 3:52 pm
I am trying to achieve something like this in TikZ: The black path should go straight up and the red one should go down bent to the right, both must look like a coil. I have tried to do this using bezier curves and arcs, but the coil decoration of the bent path looks very strange, it's pointy in some parts. What am I doing wrong? MWE: \documentclass{article} \usepackage{xcolor} \usepackage{tikz} \usetikzlibrary{decorations.pathmorphing} \begin{document} \begin{tikzpicture} \draw[-latex, decorate, decoration = {coil, aspect = 1.2}, color = red] (0,2) arc (90:-90:1); \draw[-latex, decorate, decoration = {coil, aspect = 1.2}] (0,0) -- (0,2); \draw[-latex, decorate, decoration = {coil, aspect = 1.2}] (3,0) -- (3,2); \draw[-latex, decorate, decoration = {coil, aspect = 1.2}, color = red] (3,2) .. controls (4,2) and (4,0) .. (3,0); \end{tikzpicture} \end{document}
- TikZ customize in big operators symbols, can't display big TikZ operatorsby mathrm alpha on June 13, 2026 at 8:59 am
I followed the LaTeX question reference below to adapt it to the tikz big operators version, but it didn't display in tikz "⅌" symbol. How can I define a big plus operator that works like \bigcup? ⅌ apply in tikz text symbols? % Source - https://tex.stackexchange.com/a/394912 % Posted by GuM, modified by community. See post 'Timeline' for change history % Retrieved 2026-06-13, License - CC BY-SA 3.0 \documentclass{article} \usepackage{tikz,iftex,amsmath} \usepackage{graphicx} \makeatletter \newcommand*\@bigper[1]{\vcenter{\hbox{#1$\m@th ⅌$}}} \newcommand*\bigper{% \DOTSB % omit this line if you are not using the amsmath package \mathop{% \mathchoice {\@bigper ⅌}% {\@bigper \LARGE}% {\@bigper {}}% {\@bigper \footnotesize}% }% \slimits@ % omit this line if you are not using the amsmath package } \makeatother \ifPDFTeX \usepackage[utf8]{inputenc} \else \usepackage{newunicodechar} \fi \DeclareRobustCommand{\TikZPerSign}{% \tikz[ baseline=-.25ex, x=.13em, y=.13em, line cap=round, line join=round ]{% % Fixed box: this is important for text-like behaviour. \path[use as bounding box] (-3.05,-3.35) rectangle (3.95,4.35); % 1. The horizontal ellipse \draw[line width=.05em] (0.4,0) ellipse[x radius=2.2,y radius=.7]; % 2. The main U shape \draw[line width=.05em] (-.6,1.5) .. controls (-.6,-3.2) and (.6,-3.2) .. (.6,1.5); % 3. The top-left flourish \draw[line width=.05em] (-.6,1.5) .. controls (-1.8,2.8) and (-3.0,1.5) .. (-2.2,1.2); \fill (-.5,1.9) circle[radius=.22]; % 4. The large right loop \draw[line width=.05em] (.6,1.5) .. controls (.6,4.2) and (3.5,3.2) .. (3.5,.5) .. controls (3.5,-.8) and (2.5,-1.2) .. (1.8,-1.0); }% } \ifPDFTeX \DeclareUnicodeCharacter{214C}{\TikZPerSign} \else \newunicodechar{⅌}{\TikZPerSign} \fi \begin{document} $$\sum^1_2 \bigper^3_4$$ \end{document}
- TeX chinese image poetry image text layoutby mathrm alpha on June 12, 2026 at 4:06 am
Someone helped me figure out how to create LaTeX Chinese image poetry, The vertical CJK text was not arranged according to the size of the shape. Source: https://jedi.nehs.hc.edu.tw/newsletter/306/poem.html LaTeX code I've tried with tikz text typesetting: \documentclass{article} \usepackage{tikz} \usepackage[margin=0.5in]{geometry} \usepackage{xeCJK} \definecolor{carcolor}{RGB}{242, 186, 166} \begin{document} \centering \begin{tikzpicture} % Wheels (車輪) \fill[carcolor, rounded corners=6pt] (1.8, 0.7) rectangle (2.6, 1.5); \fill[carcolor, rounded corners=6pt] (3.4, 0.7) rectangle (4.2, 1.5); % Main body of the car (主車身) \fill[carcolor, rounded corners=10pt] (0, 1) rectangle (6, 2.3); % Top cabin part (車頂) \fill[carcolor, rounded corners=12pt] (1.6, 2.2) rectangle (4.4, 3.6); \linespread{0.8}\selectfont \scriptsize % 第 1 行:叭叭(最右側,車身內) \node[text width=0.35cm, align=center] at (5.2, 1.65) {叭\\叭}; % 第 2 行:我是(車身內) \node[text width=0.35cm, align=center] at (4.8, 1.65) {我\\是}; % 第 3 行:一輛車(進入車頂邊緣) \node[text width=0.35cm, align=center] at (4.3, 1.9) {一\\輛\\車}; % 第 4 行:我可以載人(深入車頂) \node[text width=0.35cm, align=center] at (3.8, 2.3) {我\\可\\以\\載\\人}; % 第 5 行:也可以載貨物(深入車頂) \node[text width=0.35cm, align=center] at (3.3, 2.45) {也\\可\\以\\載\\貨\\物}; % 第 6 行:雖然身不大(深入車頂) \node[text width=0.35cm, align=center] at (2.8, 2.45) {雖\\然\\身\\不\\大}; % 第 7 行:卻是大力士(深入車頂) \node[text width=0.35cm, align=center] at (2.3, 2.45) {卻\\是\\大\\力\\士}; % 第 8 行:不管是跑車(進入車頂邊緣) \node[text width=0.35cm, align=center] at (1.8, 2.3) {不\\管\\是\\跑\\車}; % 第 9 行:客車或是貨車(字數多,稍微往下靠在車身與車頂間) \node[text width=0.35cm, align=center] at (1.3, 1.9) {客\\車\\或\\是\\貨\\車}; % 第 10 行:全都是(左側,車身內) \node[text width=0.35cm, align=center] at (0.8, 1.65) {全\\都\\是}; % 第 11 行:神奇 車!(最左側,車身內) \node[text width=0.35cm, align=center] at (0.4, 1.65) {神\\奇\\車\\!}; \end{tikzpicture} \end{document} I only realized how strange the text position and height were when I used it. Advanced Extension: Tikz snail's outline rotation text layout
- Drawing tikz five line style arrows in text displayby mathrm alpha on June 11, 2026 at 12:15 pm
Although a five-line arrow was unearthed, but: This is simply a very long, cramped five-line tikz arrows result, not the size of the blue arrow in the image. Furthermore, none of the arrows in the @Explorer answer (in the image) scaled down to the the same text size. This is example diagram text in: A \LLleftarrow B \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{nfold} \begin{document} \begin{tikzpicture} \draw[double equal sign distance, nfold=5, arrows=-Implies] (0,-0.7) -- (3,-0.7); \end{tikzpicture} \end{document} References: Drawing a quadruple arrow
- PGFPlots / TikZ: Filtering data from a file when the x-axis contains string valuesby joseldsm on June 10, 2026 at 9:57 am
I am generating a plot in PGFPlots/TikZ where the x-axis contains string values and the y-axis contains numerical data. The data is imported from a CSV file, and everything works correctly so far. However, when I use skip coordinates between index, the filtering is applied to the y-values and not to the x-axis categories. In this case, I want to draw only the data with the string value B. Is there a way to correctly apply this filtering to both x-axis ? Thanks! Here is the MWE. Keep in mind that in my case the data are extract from csv file. \documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotsset{compat=1.18} \pgfplotstableread{ String Value A 0 A 6 A 4 B 9 B 5 B 1 B 3 B 7 C 4 C 7 C 9 C 3 }\data \begin{document} \begin{tikzpicture} \begin{axis}[ ybar, ymin=0, xtick=data, xticklabels from table={\data}{String}, nodes near coords ] \addplot table[ x expr=\coordindex, y={Value}, skip coords between index={0}{3}, skip coords between index={8}{100} ]{\data}; \end{axis} \end{tikzpicture} \end{document}
- tikz: specifying coordiantes system in 3dby climber on January 9, 2024 at 10:14 am
currently I am working with TikZ program in latex to draw a 3d figure. I need to redefine a coordinates system in 3d. The following is a MWE I tried: \documentclass{scrreprt} \usepackage{tikz} \usetikzlibrary{3d} \begin{document} \begin{tikzpicture}[x={(0:1)},y={(60:1)},z={(30:1cm)}] \draw[->] (0,0,0) -- (1,0,0); \draw[->] (0,0,0) -- (0,1,0); \draw[->] (0,0,0) -- (0,0,1); \end{tikzpicture} \end{document} And it gives the followings figure: But when I tried to change the z coordinate as z={(30:1)} (without dimension), it gives another picture as follows: \documentclass{scrreprt} \usepackage{tikz} \usetikzlibrary{3d} \begin{document} \begin{tikzpicture}[x={(0:1)},y={(60:1)},z={(30:1)}] \draw[->] (0,0,0) -- (1,0,0); \draw[->] (0,0,0) -- (0,1,0); \draw[->] (0,0,0) -- (0,0,1); \end{tikzpicture} \end{document} So I wonder how the XYZ vectors are rotated? Are they all rotated based on the vector (1cm,0)? I didn't find the answer in the pgf manual and search for help here. Thank you for any help.
- types of systems of linear equations and intersection of planes, with tikzby Juan Leal on July 22, 2023 at 2:57 pm
Is there a simple way using tikz to graph a plane from its equation (like those of the systems on the right side, e.g. 2x +3y -z = 11), and that allows me to represent the intersection of two or three of them (even four)? If possible, I additionally need it to allow me to have flat colors in each of the planes involved and not to be represented by pieces as suggested by some of the solutions I have seen. I want to represent graphically to my students all the possibilities that can be presented with a system of linear equations with three unknowns, in a way similar to the one in the image I include. I have been reading the material related to this topic for three days and I have not found a completely satisfactory solution (or maybe there is one, but I have not appreciated it properly). I know a bit about tikz, pgfplots and tikz-3dplot (and I come from the old school of pstricks).
- How to draw on any plane with 3dtoolsby rpapa on March 24, 2022 at 3:53 pm
Salvation I am testing the 3Dtools library (https://github.com/marmotghost/tikz-3dtools). I find the idea interesting. It is possible to define a plane either by 3 points, or by a vector and a point, very well. on the other hand I did not find how to choose this plan to draw above. So I'm looking for an example of use.
- Tikz in caption leads to error even with \protect [duplicate]by aiquita on January 27, 2022 at 4:35 pm
According to Adding tikz figure in caption it suffices to add protect to make my program compile. Indeed, it compiles after adding the command, but TeX still throws an error message that the control sequence is undefined. What portion of the command definition of \circled leads to the problem? \documentclass[twoside,runningheads, oribibl, draft]{llncs} \usepackage{graphicx} \usepackage{tikz} \newcommand*\circled[1]{% \protect\tikz[baseline=(char.base)]{% \node[shape=circle, draw, inner sep=1.5pt, font=\small] (char) {#1}; }} \begin{document} \begin{figure}[h] Hello World \caption{Derivation of premise \circled{2}} \end{figure} \end{document}
- Drawing arc with superimposed label in TikZ 3Dby L Mascolo on November 21, 2021 at 11:40 am
I would like to receive some help from you. I've been able to add the label for a vector in the middle of the arrow itself in tikz3d by using a command like: \tdplotsetcoord{Mp}{\rvm}{\phm}{\thm} \path (O) -- node[sloped] (text) {$\bv{r}_{kj}(t)$} (Mp); \draw[-latex,shorten >=3mm] (O) -- (text) -- (Mp); However I would like to obtain the same with arcs. Given that I'm using the command: \tdplotdrawarc[-latex]{(O)}{0.8}{0}{\thm}{anchor=north}{$\vth_k(t)$} I cannot find a way to include it. Here is a MWE: \documentclass[tikz,border=5pt]{standalone} \usepackage{graphicx} \usepackage{tkz-euclide} % \usetkzobj{all} % obselete \usetikzlibrary{arrows.meta,angles,quotes,positioning} \usepackage{tikz-3dplot} \tdplotsetmaincoords{75}{110} \begin{document} \begin{tikzpicture}[scale=4,tdplot_main_coords] \definecolor{earth}{RGB}{0,128,0} \definecolor{moon}{RGB}{119,136,153} \pgfmathsetmacro{\rvm}{1.2} \pgfmathsetmacro{\phm}{70} \pgfmathsetmacro{\thm}{150} \coordinate (O) at (0,0,0); \draw[thick,-latex] (0,0,0) -- (1.5,0,0) node[anchor=north east]{${ I}$}; \draw[thick,-latex] (0,0,0) -- (0,1.5,0) node[anchor=north west]{${ J}$}; \draw[thick,-latex] (0,0,0) -- (0,0,1.2) node[anchor=south]{${ K}$}; % Earth \tdplotsetcoord{Ep}{0}{0}{0} % draw Moon position, theta, phi, RTN CS \tdplotsetcoord{Mp}{\rvm}{\phm}{\thm} \path (O) -- node[sloped] (text) {${r}_{kj}(t)$} (Mp); \draw[-latex,shorten >=3mm] (O) -- (text) -- (Mp); \draw[dashed,shorten >=-20pt ] (O) -- (Mpxy); \tdplotdrawarc[-latex]{(O)}{0.8}{0}{\thm}{anchor=north}{$\vartheta_k(t)$} \shade[ball color = earth] {(Ep)} circle (2.5pt); \shade[ball color = moon] {(Mp)} circle (2pt); \end{tikzpicture} \end{document}
- How to plot the 3D graph of the following three inequalities in latex (e.g., tikz/pgf)?by learner on July 9, 2021 at 9:27 am
How to plot the 3D graph of the following three inequalities in latex (tikz/pgf) ? z <= x+y+1, z <= 4x, z <= 5y. My attempt: \documentclass[12pt,leqno]{amsart} \usepackage{pgfplots} \usepackage{tikz} \begin{document} \begin{tikzpicture} \begin{axis} \addplot3 [ domain=-5:20, domain y = -3:10, samples = 20, samples y = 8, surf] {x+y+1}; \addplot3[domain=-5:20, domain y = -3:10, samples = 20, samples y = 8, surf, opacity=0.25]{4*x}; \addplot3[domain=-5:20, domain y = -3:10, samples = 20, samples y = 8, surf, opacity=0.25]{5*y}; \end{axis} \end{tikzpicture} \end{document} The above Latex code produces the above figure: But the above graph is not clear, the intersecting line of the three half-planes are not clear. Any help to draw clear image with clear intersection. Any help both with the 3D graph of the given 3 inequalities. Thanks Edit: The 2D projection of the above 3 inequalities becomes: and this is justified by the answer of @Juan Castaño.
- Drawing a circle graph with TIKZ with foreach placement and paths, yet the inbound for edges is offby Tenaka on December 1, 2020 at 5:01 pm
I want to draw a circle using TIKZ and instead of manually placing the nodes and connecting the nodes I wanted to use loops as any sane person would. Now when I wrote these, the incoming edge seems to be going to some point slightly of the node instead of to its core. In the example, I included a version with the path manually written out. I am losing my sanity here 😀 Anyone got any idea as to what is happening here? Any style critique is also very welcome! \documentclass[margin=10pt]{standalone} \usepackage{tikz} \usetikzlibrary{automata} \begin{document} \begin{tikzpicture}[nodes=state] \def \number {8} \def \radius {2cm} \def \degree {360/\number} \foreach \s in {1,...,\number} { \node at ({\degree * (\s -1)}:\radius) (\s) {$u_\s$}; } \foreach \s in {1,...,\number} { \pgfmathsetmacro\result{Mod( (\s), \number)+1} \path (\s) edge[bend right = 15] (\result); } \end{tikzpicture} \begin{tikzpicture}[nodes=state] \def \number {8} \def \radius {2cm} \def \degree {360/\number} \foreach \s in {1,...,\number} { \node at ({\degree * (\s -1)}:\radius) (\s) {$u_\s$}; } \path (1) edge[bend right = 15] (2) % edge (5) (2) edge[bend right = 15] (3) % edge (6) (3) edge[bend right = 15] (4) % edge (7) (4) edge[bend right = 15] (5) % edge (8) (5) edge[bend right = 15] (6) (6) edge[bend right = 15] (7) (7) edge[bend right = 15] (8) (8) edge[bend right = 15] (1) ; \end{tikzpicture} \end{document}
- Plane intersecting sphere with tikz and tikz-3dby B. Dors on November 3, 2020 at 3:57 pm
I'm really surprised that I couldn't find an answer to this question, but here it goes: how can I draw a plane intersecting a sphere using tikz and tikz-3dplots? I managed to do the following, using a mixture of this answer and this answer (code below): But what I really want is something like this (it's a shame and something I totally don't understand why Geogebra does not convert 3D figures to tikz): Clearly, I'm almost there. But the shading is wrong: the plane is being plotted as if it was covering the sphere, and not as if it is intersecting it. I found out here that apparently there is no way of doing the shading automatically, but I'm ok with doing it manually. The only problem is, I have no idea how to do it. I spent more than a day already trying to understand what was happening in the codes of the previous mentioned answers, as they were made for specific cases and I needed to transform them into a random sphere intersecting a random plane. I added some comments to the code with what I gathered. But I still am not sure how all of those commands work, so I can't properly identify where should I end and begin an arc to fill with some darker gray color on top of the plane plotting. I know that using an external programm to generate images would work (here is a nice example using Asymptote), but I have to add many different spheres intersecting different planes to my file, and I would prefer to be able to generate them directly in Latex with tikz, instead of having multiple figures. So my question reduces to: how to manually add the proper shading in my figure? (Notice that there is need for two shades: one for the cap of the sphere and a darker one for the back part of the sphere's cap.) Of course, an alternative code, which can be easily modified for different spheres and planes (specially planes not parallel to xy), is very welcome as well. What I have so far: \documentclass{article} \usepackage{tikz} \usepackage{tikz-3dplot} \usetikzlibrary{backgrounds, intersections} %I don't have a clear idea of what is happening here, but they are used for the plane construction \newcommand\pgfmathsinandcos[3]{% \pgfmathsetmacro#1{sin(#3)}% \pgfmathsetmacro#2{cos(#3)}% } \newcommand\LongitudePlane[3][current plane]{% \pgfmathsinandcos\sinEl\cosEl{#2} % elevation \pgfmathsinandcos\sint\cost{#3} % azimuth \tikzset{#1/.style={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}} } \newcommand\LatitudePlane[3][current plane]{% \pgfmathsinandcos\sinEl\cosEl{#2} % elevation \pgfmathsinandcos\sint\cost{#3} % latitude \pgfmathsetmacro\yshift{\cosEl*\sint} \tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} % } \newcommand\DrawLongitudeCircle[2][1]{ \LongitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=#1}} % angle of "visibility" \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} % \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1); \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1); } \newcommand\DrawLatitudeCircle[2][1]{ \LatitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=#1}} \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1); \draw[current plane,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1); } \begin{document} \begin{figure} \centering \tdplotsetmaincoords{60}{110} \begin{tikzpicture}[tdplot_main_coords, declare function={dicri(\t,\th,\ph,\R)=sin(\th)*sin(\ph)*(\R*cos(\t)) - sin(\th)*cos(\ph)*(\R*sin(\t))+ cos(\th)*(1);}] %dicri is defined according to a parametrization n+r*cos(t)*u+r*sen(t)*v, being u and v orthonormal vectors in the intersecting plane \pgfmathsetmacro{\R}{5}% \path coordinate (T) at (0,0,3) %center of circle defined by the intersection coordinate (I) at (0,0,0); \path[tdplot_screen_coords,shift={(I)},use as bounding box] (-1.2*\R,-1.2*\R)rectangle (1.2*\R,1.2*\R);%this limits the image position %draws dot+label for coordinates T and I \foreach \v/\position in {T/above,I/below} { \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$}; } \begin{scope}[tdplot_screen_coords, on background layer] \fill[ball color=white, opacity=0.8] (I) circle (\R); % determine the zeros of dicri \path[overlay,name path=dicri] plot[variable=\x,domain=0:360,samples=73] ({\x*1pt},{dicri(\x,\tdplotmaintheta,\tdplotmainphi,4)}); \path[overlay,name path=zero] (0,0) -- (360pt,0); \path[name intersections={of=dicri and zero,total=\t}] let \p1=(intersection-1),\p2=(intersection-2) in \pgfextra{\xdef\tmin{\x1}\xdef\tmax{\x2}}; \end{scope} %this has to do with finding the equation of the intersection circle, I believe \pgfmathsetmacro{\SmallR}{4} %the radius of the intersection circle is supposed as known % Draw dashed part of intersecting circle \draw[dashed] plot[variable=\t,domain=\tmin:\tmax,samples=50,smooth] ({\SmallR*cos(\t)}, {\SmallR*sin(\t)}, {3}); % Draw continuous part of intersecting circle \draw[thick,save path=\pathA] plot[variable=\t,domain=\tmax:\tmin+360,samples=50,smooth] ({\SmallR*cos(\t)}, {\SmallR*sin(\t)}, {3}); %same parametrization used in dicri. %Plane construction %% some definitions \def\angEl{35} % elevation angle \def\angAz{-105} % azimuth angle \def\angPhi{-40} % longitude of point P \def\angBeta{19} % latitude of point P %% working planes \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole \tikzset{xyplane/.style={ cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),cos(\angAz)*sin(\angEl),(0,-\H)} }, >=latex, % option for nice arrows inner sep=0pt,% outer sep=2pt,% mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt, fill=black,circle} } \LatitudePlane[equator]{\angEl}{0} %% draw xy shifted plane \filldraw[xyplane,shift={(0,0,3)},fill=gray!10,opacity=0.2] (-1.8*\R,-2.6*\R) rectangle (2.2*\R,2*\R); \end{tikzpicture} \end{figure} \end{document} EDIT: I managed to find the points where the continuous circle turns into a dashed circle using this: \path ({\SmallR*cos(\tmin)}, {\SmallR*sin(\tmin)}, {3}) coordinate (pmin) ({\SmallR*cos(\tmax)}, {\SmallR*sin(\tmax)}, {3}) coordinate (pmax); Those points are where the new shading should begin, now I'm only missing how to find the arcs of the dashed circle and of the upper sphere surface.
- LaTeX Tikz: Compare two \def argumentsby Erick Saldaña on March 11, 2020 at 4:41 pm
I am writing a macro definition that draws dimensions in the style of technical drawing. I need to perform an inequality of two of the arguments to know which is coordinate is higher up, but the console doesn't understand the condition I used as the \ifthenelse argument. % (#1,#2): Starting coordinate % (#3,#4): Ending coordinate % #5: Vertical upwards distance from the body % #6: Dimension text \usetikzlibrary{calc} \def\DimensionTop(#1,#2)(#3,#4)[#5,#6]{ \ifthenelse{#2>#4} { % If point (#1,#2) is higher than (#3,#4) \coordinate (D1) at ($ (#1,#2) + (0,#5) $); \coordinate (D2) at ($ (#3,#4) + (0,#2-#4) + (0,#5) $); } { % If point (#3,#4) is higher than (#1,#2) \coordinate (D1) at ($ (#1,#2) + (0,#4-#2) + (0,#5) $); \coordinate (D2) at ($ (#3,#4) + (0,#5) $); } \draw (#1,#2) -- (D1) -- ++(0,0.2); \draw (#3,#4) -- (D2) -- ++(0,0.2); \draw[ <->, >=latex, thin ] (D1) -- (D2) node[ fill=white, midway ] {$\mathtt{#6}$}; } The function is used like this in the main document \documentclass[border=2pt,convert={outext=.png}]{standalone} \usepackage{tikz} \usetikzlibrary{patterns} \usetikzlibrary{arrows} \begin{document} \begin{tikzpicture} % Custom command for the background grid, ignore \GuideCartesian(-2,-2)(8,8); \draw[ very thick ] (0,4) -- (2,5); \DimensionTop(0,4)(2,5)[1,1.50]; \end{tikzpicture} \end{document} Since the console doesn't understand the condition, it goes directly to the else case, which works when the point on the right is higher than the point on the left as in the picture. What would be a correct way to express this condition?
- Are there simple ways to draw parallelepipeds in tikz?by Brian Fitzpatrick on October 16, 2019 at 3:57 am
I'm trying to draw some parallelepipeds in tikz and find the task surprisingly frustrating. For example, I'd like to recreate this figure from wikipedia: I've found lots of tikz examples of cubes but none of parallelepipeds. Is there a simple way to do this?
- Intersection of a sphere and a plane knowing equationsby minhthien_2016 on March 25, 2019 at 1:27 am
I am trying draw a circle is intersection of a plane has equation 2 x − 2 y + z − 15 = 0 and the equation of the sphere is ( x − 1)^2 + ( y + 1)^ 2 + ( z − 2)^ 2 − 25 = 0. The plane cut the sphere is a circle with centre (3,-3,3 and radius r = 4. I can't draw the circle. I tried \documentclass[12pt,border = 2 mm]{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} \usetikzlibrary{arrows,calc,backgrounds} \begin{document} \tdplotsetmaincoords{60}{110} \begin{tikzpicture}[tdplot_main_coords] \path coordinate (T) at (3,-3,3) coordinate (I) at (1,-1,2); \foreach \v/\position in {T/above,I/below} { \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$}; } \draw[dashed] (T) circle[radius={4}]; \begin{scope}[tdplot_screen_coords, on background layer] \pgfmathsetmacro{\R}{5}% \fill[ball color=purple, opacity=1.0] (I) circle (\R); \end{scope} \end{tikzpicture} \end{document} How can I draw the circle?
- TikZ, draw a 3D intersection of planesby BowPark on April 19, 2018 at 11:05 am
A first example of intersection between two planes is already shown in this answer. I would like to use TikZ. I already tested that code, but it has a different axes layout (the axes in the linked answer are like a box containing the planes; the required axes here are instead the cartesian ones), a different position of the planes and a different fill pattern for the planes: I don't know how to modify it according to my requirements. The final result should be like the following image, with these differences: only its left part is to be considered (the right part can be completely ignored); the planes in my picture have a vertical intersection line (instead of the horizontal intersection line of the picture); the text line of intersection and its arrow are not necessary. How to accomplish this (with or without the code in the linked answer)?
- Pie chart size from Bordaigorlby Laura K on April 27, 2017 at 7:10 pm
I have been using this great pie chart code: How to draw Bar & Pie Chart The code is from Bordaigorl. I was wondering if anyone can see how it is possible to have two pie charts in the same environment with different sizes. The part of the code that is responsible for this is "scale" when you call the function pie chart: \begin{tikzpicture} [ pie chart, slice type={g}{giallo}, slice type={A}{rosso}, slice type={B}{blu}, pie values/.style={font={\small}}, scale=2 ] \pie{t=1, A in power}{66/g,34/A} \pie[xshift=2.2cm]% {t=2, B in power}{33/g,33/B} \end{tikzpicture} My question is: does anyone see how to create two "types" of pies, one with scale=2 and another with scale=2.5, for example? For the purpose of understanding, I will post an MWE based on the whole code created by Bordaigorl here. What I would like is to have the left pie chart in one scale and the pie chart on the right in another scale. Please note that I am not the one who designed this code and credit must be given to Bordaigorl: \documentclass[border=10pt,multi,tikz]{standalone} \definecolor{rosso}{RGB}{220,57,18} \definecolor{giallo}{RGB}{255,153,0} \definecolor{blu}{RGB}{102,140,217} \definecolor{verde}{RGB}{16,150,24} \definecolor{viola}{RGB}{153,0,153} \makeatletter \tikzstyle{chart}=[ legend label/.style={font={\scriptsize},anchor=west,align=left}, legend box/.style={rectangle, draw, minimum size=5pt}, axis/.style={black,semithick,->}, axis label/.style={anchor=east,font={\tiny}}, ] \tikzstyle{bar chart}=[ chart, bar width/.code={ \pgfmathparse{##1/2} \global\let\bar@w\pgfmathresult }, bar/.style={very thick, draw=white}, bar label/.style={font={\bf\small},anchor=north}, bar value/.style={font={\footnotesize}}, bar width=.75, ] \tikzstyle{pie chart}=[ chart, slice/.style={line cap=round, line join=round, very thick,draw=white}, pie title/.style={font={\bf}}, slice type/.style 2 args={ ##1/.style={fill=##2}, values of ##1/.style={} } ] \pgfdeclarelayer{background} \pgfdeclarelayer{foreground} \pgfsetlayers{background,main,foreground} \newcommand{\pie}[3][]{ \begin{scope}[#1] \pgfmathsetmacro{\curA}{90} \pgfmathsetmacro{\r}{1} \def\c{(0,0)} \node[pie title] at (90:1.3) {#2}; \foreach \v/\s in{#3}{ \pgfmathsetmacro{\deltaA}{\v/100*360} \pgfmathsetmacro{\nextA}{\curA + \deltaA} \pgfmathsetmacro{\midA}{(\curA+\nextA)/2} \path[slice,\s] \c -- +(\curA:\r) arc (\curA:\nextA:\r) -- cycle; \pgfmathsetmacro{\d}{max((\deltaA * -(.5/50) + 1) , .5)} \begin{pgfonlayer}{foreground} \path \c -- node[pos=\d,pie values,values of \s]{$\v\%$} +(\midA:\r); \end{pgfonlayer} \global\let\curA\nextA } \end{scope} } \newcommand{\legend}[2][]{ \begin{scope}[#1] \path \foreach \n/\s in {#2} { ++(0,-10pt) node[\s,legend box] {} +(5pt,0) node[legend label] {\n} } ; \end{scope} } \begin{document} \begin{tikzpicture} [ pie chart, slice type={g}{giallo}, slice type={A}{rosso}, slice type={B}{blu}, pie values/.style={font={\small}}, scale=2 ] \pie{1}{66/g,34/A} \pie[xshift=2.2cm]% {2}{33.3/g,33.3/B,33.3/A} \end{tikzpicture} \end{document} I apologize if that is an obvious question. I've tried in 2 differents ways and they were all not succesful: I've tried to remove the scale from the preamble on tikz and added scale=2 when was calling pie function: \pie[xshift=2.2cm, scale=2]{2}{33.3/g,33.3/B,33.3/A} I've also tried to create two functions in the preamble of the document, one pie1 and another pie2. The code doesn't compile Thank you!
- How to draw a graph with ring in latex?by Scott Shao on September 8, 2015 at 1:02 am
As the title tells, how to draw a graph with ring in latex? I have learned that I can use forest to draw a tree in latex. For example, using following code, I can have one simple binary tree.1->2, 1->3. \begin{forest} for tree={circle,draw} [1[2][3]] \end{forest} Then, Im wondering how to draw a graph with ring. For example, how can I add another edge between 1 and 2 so that there is ring between node 1 and 2. 1 -> 2, and 2->1. Also, I'm wondering how to draw a self ring. i.e., 1->1(an egde starting from node 1 and ending at node 1)
- Draw Spiral Cone TikZby Sebastian on September 13, 2013 at 3:50 pm
Im trying to do a spiral cone in TikZ. I dont know what is the best way to do this.
- TikZ: two ellipses in different planesby dustin on July 12, 2013 at 2:14 am
How can show that two ellipses are in different planes? \documentclass[convert = false, border = 1cm]{standalone} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \pgfmathsetmacro{\as}{2}; \pgfmathsetmacro{\bs}{1.95}; \pgfmathsetmacro{\cs}{sqrt(\as^2 - \bs^2)} \pgfmathsetmacro{\al}{3}; \pgfmathsetmacro{\bl}{2.25}; \pgfmathsetmacro{\cl}{sqrt(\al^2 - \bl^2)} \pgfmathsetmacro{\xs}{abs(\cs - \cl)} \draw (0, 0) ellipse [x radius = \as cm, y radius = \bs cm]; \draw (\xs, 0) ellipse [x radius = \al cm, y radius = \bl cm]; \filldraw[black] (-\cs, 0) circle [radius = .1cm]; \filldraw[black] (-\cl + \xs, 0) circle [radius = .1cm]; \end{tikzpicture} \end{document} From the image, we see that both ellipses are in the same plane. How can I rotate the small ellipse to make it appear as if the smaller ellipse is in a different plane? Using rotate around doesn't achieve that look. Edit 2: I am a little hesitant about using xslant and yslant since it appears that the ellipse is being shifted and stretched. Here is a poor picture(my phone camera flash refused to work) of two ellipse in different planes. If adjust my smaller ellipse, it stretches and appears to shift dramatically. From the image below, the focus appears to be in the center of smaller ellipse now and it has elongated. Edit: So I found this post Why isn't the arc drawn on the good plane using tikz-3dplot in Tait-Bryan convention but I don't fully understand the code. However, the poster was able to rotate ellipse and have a better visual appeal and the poster could define the plane it is in such as xy, yz, and xz. How could I adapt this code to my situation?
- tikz-3dplot rotation around the x-axisby asm on March 23, 2013 at 10:27 pm
I'm trying to create a simple spherical quadrant grid using the tikz-3dplot package. The longitudinal grid lines look fine but when I try to create the latitudinal lines I get really strange results that I don't understand. I was expecting to see a series of latitude arcs rotating around the x-axis (so they're not quite the same as latitude lines). Instead, it appears that my attempt to rotate around the x-axis is rotating around all three axes. I'm not sure what I'm doing wrong. \documentclass{article} \usepackage{tikz} \usepackage{tikz-3dplot} \begin{document} \tdplotsetmaincoords{60}{155} \usetikzlibrary{3d} \begin{tikzpicture}[scale=5,tdplot_main_coords] \tikzstyle{grid}=[thin,color=red,tdplot_rotated_coords] \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$}; \draw[thick,->] (0,0,0) -- (-1,0,0); \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$}; \foreach \rot in {0, 30, 60, 90} { \tdplotsetrotatedcoords{\rot}{0}{0}; \tdplotdrawarc[grid]{(0,0,0)}{1}{0}{180}{}{}; } \foreach \rot in {-90, -60, -30, 0, 30, 60, 90} { \tdplotsetrotatedcoords{\rot}{90}{0}; \tdplotdrawarc[grid]{(0,0,0)}{1}{90}{180}{}{}; } \end{tikzpicture} \end{document} Edit: After more investigation it appears that attempting to rotate around the x-axis actually rotates around the z-axis, as can be clearly seen in this image. Placing the \rot in the x- or z-position has the same effect.
- Using TikZ inside a figure captionby Nico Schlömer on May 16, 2012 at 1:52 pm
I have a PNG plot with a couple of black patches in it, and I'd like to refer to it in the \caption of the figure. According to the TikZ manual, I'd have to \tikz \fill[black] (1ex,1ex) circle (1ex); which works perfectly outside a \caption. Using this inside a \caption, though, leaves me with the compile error ! Use of \use@pgflibrary doesn't match its definition. \pgfutil@ifnextchar ...1\def \pgfutil@reserved@a { #2}\def \pgfutil@reserved@... l.375 ...blah blah.} ? The following produces the compile error \documentclass{article} \usepackage{tikz} \begin{document} \tikz \fill[orange] (1ex,1ex) circle (1ex); \begin{figure} \caption{\tikz \fill[orange] (1ex,1ex) circle (1ex);} \end{figure} \end{document} Any hints here?