TikZ
- minimal simple pgfdeclareshape not workingby MattW on February 9, 2025 at 12:48 am
I am trying to learn how to generate a new shape for tikz. On the short term I want a minimal pdfdeclareshape that draws a filled rectangle. My eventual goal is a filled figure with a protrusion from a rectangle. I'd prefer not to use inherit until I have a good understanding of how it all works. The following runs, but does not show any figure. Any ideas what it would take? \documentclass[preview]{standalone} \usepackage{tikz} \usetikzlibrary{positioning} \begin{document} \makeatletter \pgfdeclareshape{myrect}{ \savedanchor\basepoint{\pgfpointorigin} \anchor{center}{\basepoint} \backgroundpath{% \pgfpathmoveto{\pgfqpoint{+0pt}{+0pt}}% \pgfpathmoveto{\pgfqpoint{+20pt}{+0pt}}% \pgfpathmoveto{\pgfqpoint{+20pt}{+20pt}}% \pgfpathmoveto{\pgfqpoint{+0pt}{+20pt}}% \pgfpathclose% }% \beforebackgroundpath{\pgfusepath{fill,stroke}}% } \makeatother hello\hfil\break \begin{tikzpicture} \draw (0,0) node[myrect] {}; \end{tikzpicture} \hfil\break world \end{document}
- 3D rotation of nodes and shapesby Jellby on February 8, 2025 at 3:41 pm
Is there some way to create an image like the one below with TikZ, with the rotations being done right (instead of by manually slanting/scaling until it kind of looks okay-ish, as I did with inkscape)? I'd like to be able to apply an arbitrary 3D rotation to a node or planar shape. The closest I've found is Polar triangle in TiKz, but that addresses only the sphere part, and not the transformation. EDIT: OK, I figured out the canvas is * plane at * and transform shape keys, and I was able to reproduce the figure (based on the link above). Now I just need to express a rotation around an arbitrary axis as a sequence of x,y,z rotations, but that's a maths problem. \documentclass {standalone} \usepackage {tikz} \usetikzlibrary{3d} \usetikzlibrary{calc} \usetikzlibrary{math} % isometric axes \def\angi{35} \def\angii{45} \pgfmathsetmacro\xx{sin(\angii)} \pgfmathsetmacro\xy{-cos(\angii)*sin(\angi)} \pgfmathsetmacro\yx{sin(\angii-90)} \pgfmathsetmacro\yy{-cos(\angii-90)*sin(\angi)} \pgfmathsetmacro\zx{0} \pgfmathsetmacro\zy{cos(\angi)} % some functions (cross products) \tikzmath% {% function crossx(\mx,\my,\mz,\nx,\ny,\nz) {% cross product, x coordinate, normalized \pxx = \my*\nz-\mz*\ny; \pyy = \mz*\nx-\mx*\nz; \pzz = \mx*\ny-\my*\nx; return {\pxx/sqrt(\pxx*\pxx+\pyy*\pyy+\pzz*\pzz)}; }; function crossy(\mx,\my,\mz,\nx,\ny,\nz) {% cross product, y coordinate, normalized \pxx = \my*\nz-\mz*\ny; \pyy = \mz*\nx-\mx*\nz; \pzz = \mx*\ny-\my*\nx; return {\pyy/sqrt(\pxx*\pxx+\pyy*\pyy+\pzz*\pzz)}; }; function crossz(\mx,\my,\mz,\nx,\ny,\nz) {% cross product, z coordinate, normalized \pxx = \my*\nz-\mz*\ny; \pyy = \mz*\nx-\mx*\nz; \pzz = \mx*\ny-\my*\nx; return {\pzz/sqrt(\pxx*\pxx+\pyy*\pyy+\pzz*\pzz)}; }; } \newcommand{\greatcircle}[6] % pole x, y, z, color, two orientation factors (+1/-1) {% \coordinate (P) at (#1,#2,#3); % pole \coordinate (N) at ($(0,0,0)!#6*1.25cm!(P)$); % these points are \coordinate (S) at ($-1*(N)$); % used to clip the \coordinate (E) at ($(0,0,0)!-1.25cm!270:(P)$); % ellipses \coordinate (W) at ($-1*(E)$); % ... \coordinate (NW) at ($(N)+(W)$); \coordinate (NE) at ($(N)+(E)$); \coordinate (SW) at ($(S)+(W)$); \coordinate (SE) at ($(S)+(E)$); \pgfmathsetmacro\ptheta{atan2(#2,#1)} % pole, spherical coordinate theta \pgfmathsetmacro\pphi {#5*acos(#3)} % pole, spherical coordinate phi \begin{scope} \clip (W) -- (SW) -- (SE) -- (E) -- cycle; \draw[rotate around z=\ptheta,rotate around y=\pphi,% canvas is xy plane at z=0,#4] (0,0) circle (1); \end{scope} } \newcommand{\mylabel} {% \begin{scope}[canvas is xz plane at y=1] \node[draw,thick,inner sep=2pt,transform shape] at (0,0) {\sffamily\bfseries R}; \end{scope} } \begin{document} \begin{tikzpicture}[line cap=round,line join=round,scale=2,% x={({\xx cm,\xy cm})},y={(\yx cm,\yy cm)},z={(\zx cm,\zy cm)}] % points A, B, C in spherical coordinates \def\atheta{0} \def\aphi {0} \def\btheta{0} \def\bphi {90} \def\ctheta{90} \def\cphi {90} % points A, B, C in cartesian coordinates \pgfmathsetmacro\ax{cos(\atheta)*sin(\aphi)} \pgfmathsetmacro\ay{sin(\atheta)*sin(\aphi)} \pgfmathsetmacro\az{cos(\aphi)}); \pgfmathsetmacro\bx{cos(\btheta)*sin(\bphi)} \pgfmathsetmacro\by{sin(\btheta)*sin(\bphi)} \pgfmathsetmacro\bz{cos(\bphi)}); \pgfmathsetmacro\cx{cos(\ctheta)*sin(\cphi)} \pgfmathsetmacro\cy{sin(\ctheta)*sin(\cphi)} \pgfmathsetmacro\cz{cos(\cphi)}); % polar points P, Q, R in cartesian coordinates \pgfmathsetmacro\px{crossx(\ax,\ay,\az,\bx,\by,\bz)} \pgfmathsetmacro\py{crossy(\ax,\ay,\az,\bx,\by,\bz)} \pgfmathsetmacro\pz{crossz(\ax,\ay,\az,\bx,\by,\bz)} \pgfmathsetmacro\qx{crossx(\cx,\cy,\cz,\ax,\ay,\az)} \pgfmathsetmacro\qy{crossy(\cx,\cy,\cz,\ax,\ay,\az)} \pgfmathsetmacro\qz{crossz(\cx,\cy,\cz,\ax,\ay,\az)} \pgfmathsetmacro\rx{crossx(\bx,\by,\bz,\cx,\cy,\cz)} \pgfmathsetmacro\ry{crossy(\bx,\by,\bz,\cx,\cy,\cz)} \pgfmathsetmacro\rz{crossz(\bx,\by,\bz,\cx,\cy,\cz)} % triangles \greatcircle{\px}{\py}{\pz}{black}{-1}{1} \greatcircle{\qx}{\qy}{\qz}{black}{ 1}{1} \greatcircle{\rx}{\ry}{\rz}{black}{-1}{1} % sphere and axes \draw (0,0,0) circle (1 cm); % labels \mylabel \begin{scope}[rotate around z=-90] \mylabel \end{scope} \begin{scope}[rotate around x=90] \mylabel \end{scope} \begin{scope}[rotate around z=\angii-90]\begin{scope}[rotate around x=\angi] \mylabel \end{scope}\end{scope} \end{tikzpicture} \end{document}
- \tdplottransformrotmain{}{}{} equivalent in luacodeby Jasper on February 8, 2025 at 5:47 am
I am trying to recreate the \tdplottransformrotmain{}{}{} command in luacode. The command should input a point and a ZYZ rotation matrix, and output the point's image after it undergoes that rotation. I don't know how rotation matrices work, so I used AI to get the code (I also wrote a lot myself, and much of it is not shown). It is transforming the points wrong. In the following code, the shape should be oriented so that it makes a circle on the viewing plane. Clearly it is not doing so. I am seeking assistance in making this important function. \documentclass{beamer} \beamertemplatenavigationsymbolsempty \usepackage{ tikz ,tikz-3dplot ,luacode } \begin{luacode} -- Convert degrees to radians function deg_to_rad(degrees) return degrees * math.pi / 180 end -- Sine function for degrees function sind(degrees) return math.sin(deg_to_rad(degrees)) end -- Cosine function for degrees function cosd(degrees) return math.cos(deg_to_rad(degrees)) end function sphere(azimuth, elevation) local x = math.cosd(elevation)*math.cosd(azimuth) local y = math.cosd(elevation)*math.sind(azimuth) local z = math.sind(elevation) return {x, y, z} end elevation = 90-30 azimuth = 130 camera = { sphere(elevation, azimuth)[2] ,-sphere(elevation, azimuth)[1] ,sphere(elevation, azimuth)[3] } function transformrotmain(point, angles) -- Extract the rotation angles (alpha, beta, gamma) local alpha, beta, gamma = angles[1], angles[2], angles[3] -- Precompute the sines and cosines of the angles for efficiency local c1 = cosd(alpha) local s1 = sind(alpha) local c2 = cosd(beta) local s2 = sind(beta) local c3 = cosd(gamma) local s3 = sind(gamma) -- Apply the ZYZ rotation matrix to the point local x_new = c1 * c2 * c3 - s1 * s3 + point[1] * (c1 * s2 * s3 + s1 * c3) + point[2] * (s1 * c2 * c3 + c1 * s3) + point[3] * (s2 * s3) local y_new = s1 * c2 * c3 + c1 * s3 + point[1] * (s1 * s2 * s3 - c1 * c3) - point[2] * (c1 * c2 * s3 - s1 * c3) + point[3] * (-s2 * c3) local z_new = -s2 * c3 + point[1] * (-c2 * s3) + point[2] * (c2 * c3) + point[3] * (c2 * s2) -- Return the transformed point return {x_new, y_new, z_new} end \end{luacode} \directlua{rotation = 1.7391304347826086} \begin{document} \begin{frame}[fragile] \centering \tdplotsetmaincoords{90-\directlua{tex.print(elevation)}}{\directlua{tex.print(azimuth)}} \begin{tikzpicture}[tdplot_main_coords,scale=0.97] \path[white,tdplot_screen_coords] (-\textwidth/2,-\textheight/2) rectangle (\textwidth/2,\textheight/2); \clip[tdplot_screen_coords] (-\textwidth/2,-\textheight/2) rectangle (\textwidth/2,\textheight/2); \begin{luacode} for x = -90, 90, 10 do for y = 0, 360, 10 do startx = transformrotmain({sphere(y,x)[1],sphere(y,x)[2],sphere(y,x)[3]},{30,30,30})[1] starty = transformrotmain({sphere(y,x)[1],sphere(y,x)[2],sphere(y,x)[3]},{30,30,30})[2] startz = transformrotmain({sphere(y,x)[1],sphere(y,x)[2],sphere(y,x)[3]},{30,30,30})[3] endx = transformrotmain({sphere(y+10,x)[1],sphere(y+10,x)[2],sphere(y+10,x)[3]},{30,30,30})[1] endy = transformrotmain({sphere(y+10,x)[1],sphere(y+10,x)[2],sphere(y+10,x)[3]},{30,30,30})[2] endz = transformrotmain({sphere(y+10,x)[1],sphere(y+10,x)[2],sphere(y+10,x)[3]},{30,30,30})[3] tex.print(string.format("\\draw[ultra thin] (%f,%f,%f) -- (%f,%f,%f);",startx,starty,startz,endx,endy,endz)) end end \end{luacode} \end{tikzpicture} \end{frame} \end{document}
- pgfdeclareshape fails with 'Undefined control sequence.' \pgf [duplicate]by MattW on February 7, 2025 at 10:01 pm
I'm trying to create a simple shape for tikz-pgf. This is my first shot at this kind of thing. The shape is intended to (eventually) be attached to a rectangle to indicate a directional port. My first step is to try to get something to show up. But I'm getting ! Undefined control sequence. <argument> \pgf with the location being the final } of the expression below. Any ideas what I'm missing? % __ ___ % | |_ |_ | % base->| _|<--tip--> _| |<-base % |__| |___| % ^-lfinger ^-rbutton \pgfdeclareshape{lfinger}{ \setlength\pgf@sz{10pt}% \savedanchor\basepoint{% \pgf@x=0% \pgf@y=.5\pgf@sz% } \anchor{base}{\basepoint} \backgroundpath{% {% \pgfsetlength\pgf@xa0\pgf@sz \pgfsetlength\pgf@ya.5\pgf@sz% \pgfsetlength\pgf@xb0\pgf@sz \pgfsetlength\pgf@yb1\pgf@sz% \pgfsetlength\pgf@xc.5\pgf@sz \pgfsetlength\pgf@yc1\pgf@sz% \pgfsetlength\pgf@xd.8\pgf@sz \pgfsetlength\pgf@yd.7\pgf@sz% \pgfsetlength\pgf@xe.8\pgf@sz \pgfsetlength\pgf@ye.5\pgf@sz% \pgfsetlength\pgf@xf.8\pgf@sz \pgfsetlength\pgf@yf.3\pgf@sz% \pgfsetlength\pgf@xg.5\pgf@sz \pgfsetlength\pgf@yg.3\pgf@sz% \pgfsetlength\pgf@xh.5\pgf@sz \pgfsetlength\pgf@yh0\pgf@sz% \pgfsetlength\pgf@xi0\pgf@sz \pgfsetlength\pgf@yi0\pgf@sz% \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}% \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}% \pgfpathmoveto{\pgfqpoint{\pgf@xc}{\pgf@yc}}% \pgfpathmoveto{\pgfqpoint{\pgf@xd}{\pgf@yd}}% \pgfpathmoveto{\pgfqpoint{\pgf@xf}{\pgf@yf}}% \pgfpathmoveto{\pgfqpoint{\pgf@xg}{\pgf@yg}}% \pgfpathmoveto{\pgfqpoint{\pgf@xh}{\pgf@yh}}% \pgfpathmoveto{\pgfqpoint{\pgf@xi}{\pgf@yi}}% \pgfpathclose% }% }% }
- Drawing rods at various positions and angles along a parabolaby Ismael Joaquim on February 6, 2025 at 10:40 am
\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % Define the parabola \coordinate (A) at (0,4); % Vertex of the parabola \coordinate (B) at (-3,0); % Left endpoint \coordinate (C) at (3,0); % Right endpoint \draw[thick] (A) parabola (B); % Draw left half of the parabola \draw[thick] (A) parabola (C); % Draw right half of the parabola % Draw a dashed grid for reference \draw[dashed, step=0.5] (-3,0) grid (3,4); % Define the length of the rod \def\rodLength{1.5} % Length of the rod % Draw the rod at various positions along the parabola \foreach \x in {-2.5, -1.5, -0.5, 0.5, 1.5, 2.5} { % Calculate the y position on the parabola using the equation y = 4 - (x^2)/2.25 \pgfmathsetmacro{\y}{4 - (\x * \x) / 2.25} % Calculate the slope of the parabola at this point (dy/dx = -x/1.125) \pgfmathsetmacro{\slope}{-\x / 1.125} % Calculate the rotation angle for the rod (in degrees) \pgfmathsetmacro{\angle}{atan(\slope)} % Draw the rod (thick blue line) rotated at the calculated angle \draw[line width=2mm, color=blue, rotate around={\angle:(\x,\y)}] (\x - \rodLength/2, \y) -- (\x + \rodLength/2, \y); % Mark the center of mass (red dot) \filldraw[red] (\x, \y) circle (2pt); } \end{tikzpicture} \end{document} Current result:
- Perpetual annuity actuarial chartby José on February 6, 2025 at 8:58 am
I am trying to reproduce the following timeline chart in latex but I do not know how to add the zigzag line. I provide, the MWE: \documentclass{article} \usepackage{graphicx} \usepackage{tikz} \usepackage{tkz-tab} \usetikzlibrary{positioning} \begin{document} \begin{figure} \centering \begin{tikzpicture} \draw[line width=1pt] (0,0) -- node[below=1mm,pos=0.6,scale=2] {$\cdots$} (10,0)node[right=4mm]{(periods)}; \foreach \x/\y in {0/0,1/1,2/2,3/3,9/$n-1$,10/$n$}{ \draw[line width=1pt] (\x,-2mm)node[below](\x){\strut\y} -- (\x,2mm)node[above]{$\$ 1$}; } \draw[-latex] (0,-7mm) -- +(0,-10mm)node[below]{$A_{ni}$}; \draw[-latex] (10,-7mm) -- +(0,-10mm)node[below]{$S_{ni}$}; \end{tikzpicture} \caption{Annuity Scheme} \label{fig:M2} \end{figure} \end{document}
- How to add parallel lines in tikzby Mr.Price on February 5, 2025 at 8:23 pm
I have the following angle and I want to add two parallel lines. I could put the same pos to both A and A' and B and B' but I don't want to have an equal distance from point O to these points. How can I figure out what pos to use? Or mybe there is another way? In the picture I like the angle of first line and I'd like to make the second one parallel to the first one. \documentclass[tikz, margin=2mm]{standalone} \usetikzlibrary{angles, quotes} \usepackage{amssymb} \usetikzlibrary {arrows.meta, shapes.geometric, trees, shapes, backgrounds,intersections, patterns,decorations.markings, calc} \usepackage{pgfplots} \usepgfplotslibrary{units} \usetikzlibrary{positioning} \usepackage{amsmath, amssymb} \usepackage{siunitx} \usepackage{tikz-3dplot} \usepackage[dvipsnames]{xcolor} \usepackage{polski} \begin{document} \tikzset{background grid/.append style={step=.5cm, ultra thin, dashed, gray!50}} \begin{tikzpicture}[show background grid, >=Stealth] \draw[] (8,0) coordinate (S) -- (0,0) coordinate (O) -- (40:8) coordinate (E); \path (O) -- (S) coordinate[pos=0.75] (B'); \path (O) -- (S) coordinate[pos=0.45] (A'); \path (O) -- (E) coordinate[pos=0.65] (B); \path (O) -- (E) coordinate[pos=0.35] (A); \draw[draw, fill=Black] (0,0) circle(1.5pt); \draw[draw, fill=Black] (B') circle(1.5pt); \draw[draw, fill=Black] (B) circle(1.5pt); \draw[draw, fill=Black] (A') circle(1.5pt); \draw[draw, fill=Black] (A) circle(1.5pt); \draw[] ($(A)!-1!(A')$) -- ($(A)!1.7!(A')$); \draw[] ($(B)!-0.4!(B')$) -- ($(B)!1.4!(B')$); \pic [ draw, -, fill=Orange, fill opacity=0.25, text opacity=1.0, angle radius=12mm, angle eccentricity=0.6, "$\alpha$"] {angle = S--O--E}; \end{tikzpicture} \end{document}
- How to fix tcolorbox width for two tikz subfiguresby armaninux on February 5, 2025 at 8:07 pm
In the following example two tikz plots should fill the gray tcolorbox entirely (or rather, the tcolorbox should wrap nicely around the two tikz plots, with no extra space to the right). I tried a few tcolorbox options for width but with terrible results. \documentclass[10pt,a4paper]{book} \usepackage[absolute,overlay]{textpos} \usepackage[most]{tcolorbox} \usepackage{subcaption} % --- plots \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{polar} \newenvironment{starplot}[1]{% \begin{tikzpicture}[scale=0.6,line width=1pt] \draw[darkgray,fill=darkgray] (0,0) circle (6); \draw[gray!10] (0,0) circle (6.8); #1 }{\end{tikzpicture}} \begin{document} % I get this: \begin{textblock}{16}(3, 1) \begin{figure}[ht] \begin{tcolorbox}[colframe=black] \begin{subfigure}[]{0.30\textwidth} \resizebox{\linewidth}{!}{% \begin{starplot} \end{starplot}% } \end{subfigure} \begin{subfigure}[]{0.30\textwidth} \resizebox{\linewidth}{!}{% \begin{starplot} \end{starplot}% } \end{subfigure} \end{tcolorbox} \end{figure} \end{textblock} % But it should rather be something like this: \begin{textblock}{10}(3, 5) \begin{figure}[ht] \begin{tcolorbox}[colframe=black] \begin{subfigure}{0.45\textwidth} \includegraphics[width=\textwidth]{example-image-a} \caption{First subfigure.} \label{fig:first} \end{subfigure} \hfill \begin{subfigure}{0.45\textwidth} \includegraphics[width=\textwidth]{example-image-b} \caption{Second subfigure.} \label{fig:second} \end{subfigure} \end{tcolorbox} \caption{A figure with two subfigures wrapped in a rectangle frame.} \label{fig:figures} \end{figure} \end{textblock} \end{document} PS: I happen to like tcolorbox for the looks, but any other tool will do as long as it gives me a background and a frame.
- Chronos package: showing connections between eventsby tnt on February 5, 2025 at 7:30 pm
I am using the chronos package to make a timeline. I've picked the date centric theme since I like its minimal look. I'm having trouble figuring out how to add curved lines that connect one chronosevent to another. This is my minimal working example: \documentclass[a4paper,12pt]{article} \usepackage{chronos} \begin{document} \begin{figure} \centering \begin{chronos} [ date centric, timeline={ start date=1965, end date=2026, }, ] \chronosevent {date={2000}, yshift=5pt, special date={2000}, name=C, name content=Theory C} \chronosevent {date={1984}, as is, name=B, name content=Theory B, yshift=30pt} \chronosevent {date={1978}, as is, name=A, name content=Theory A, yshift=5pt} \chronosmaintitle {name=Theories of X, at=current bounding box.north west,yshift=30pt,anchor=north west} \end{chronos} \end{figure} \end{document} And this is what I want to achieve (the orange line going from Theory A to Theory B): I have tried using \draw [line width=1pt, orange] (A.north west) -- (B.south east); but it's doing something different from what I want: Could someone help out?
- Drawing a function on circular space S^1 in tikz [closed]by Jonathan Cellucci on February 5, 2025 at 3:08 pm
I need the x axes being a circle and the y axis pointing up as usual so I can draw functions with these axes.
- Faster and more robust alternatives to pgfmath [duplicate]by Jasper on February 5, 2025 at 8:53 am
I have been working in pgfmath for a while, but it is proving to be too slow for some diagrams. I want to know what some faster alternatives to pgfmath are. For example: luacode, gnuplot, matplotlib, external software, etc. In particular, the following code both takes forever to run, and runs into dimensions too large issues. I would like to make vector fields which are more complicated, but finding thousands of vectors, with each being based on several charged points, is quite resource intensive. [Note: There is a typeout in the log which will tell you how far along the code is. It takes several seconds to complete one iteration of the inner for-loop (of which there are 15 for each iteration of the outer one). The outer one loops 15 times as well. I intend to make this bigger once I get my hands on faster software. So an estimate of the time this takes is (15*4)*15/60 seconds ~ >13 minutes] \documentclass[tikz, border=3.14mm]{standalone} \usepackage{tikz-3dplot} % https://tex.stackexchange.com/a/734099/319072 \ExplSyntaxOn % Create a new named segment list % #1: name of the new list \NewDocumentCommand \NewSegmentList { m } { \seq_new:c { g__jasper_segment_list_#1_seq } } % Add a segment to a named segment list % #1: name of the list % #2: sorting data (should be a float) % #3: additional data you want to retrieve (should include assignments storing % your data into locally used variables) \NewDocumentCommand \AddSegment { m m m } { \seq_gput_right:ce { g__jasper_segment_list_#1_seq } { { \fp_eval:n {#2} } { \exp_not:n {#3} } } } % Sort a named segment list % #1: > for ascending order, < for descending order (might be counter intuitive) % #2: name of the list \NewDocumentCommand \SortSegmentList { O{>} m } { \seq_gsort:cn { g__jasper_segment_list_#2_seq } { \fp_compare:nNnTF { \use_i:nn ##1 } #1 { \use_i:nn ##2 } \sort_return_swapped: \sort_return_same: } } % Loop over the elements of a list. Each item will be used inside of groups. % #1: name of the list % #2: code to execute inside each elements group after whatever was stored was % run \NewDocumentCommand \LoopOverSegmentList { m m } { \seq_map_inline:cn { g__jasper_segment_list_#1_seq } { \group_begin: \use_ii:nn ##1 #2 \group_end: } } % For debugging purposes, show the contents of a named segment list. % #1: name of the list \NewDocumentCommand \ShowSegmentList { m } { \seq_show:c { g__jasper_segment_list_#1_seq } } \ExplSyntaxOff \NewSegmentList{helix} \begin{document} \tdplotsetmaincoords{60}{130} \begin{tikzpicture}[tdplot_main_coords] \foreach[parse=true,count=\i] \t in {0,60,...,6*360} { \pgfmathsetmacro{\px}{cos(\t)} \pgfmathsetmacro{\py}{sin(\t)} \pgfmathsetmacro{\pz}{\i/40} \pgfmathsetmacro{\ppx}{cos(\t+10)} \pgfmathsetmacro{\ppy}{sin(\t+10)} \pgfmathsetmacro{\ppz}{\i/40} \ExpandArgs{nne}\AddSegment{helix} {} {% \def\noexpand\px{\px}% \def\noexpand\py{\py}% \def\noexpand\pz{\pz}% \def\noexpand\ppx{\ppx}% \def\noexpand\ppy{\ppy}% \def\noexpand\ppz{\ppz}% }% } \draw[smooth,samples=300,domain=0:6*360,red] plot ({cos(\x)},{sin(\x)},{\x/60/40}); \foreach \x in {-3,-2.5,...,3} { \typeout{X is \x} \foreach \y in {-3,-2.5,...,3} { \typeout{Y is \y} \foreach \z in {-3,-2.5,...,3} { \pgfmathsetmacro{\vx}{0} \pgfmathsetmacro{\vy}{0} \pgfmathsetmacro{\vz}{0} \LoopOverSegmentList{helix} { \pgfmathsetmacro{\xpx}{\x-\px} \pgfmathsetmacro{\ypy}{\y-\py} \pgfmathsetmacro{\zpz}{\z-\pz} \pgfmathsetmacro{\length}{% \fpeval{sqrt((\xpx)^2+(\ypy)^2+(\zpz)^2)}% } \pgfmathparse{\length!=0} \ifnum\pgfmathresult=1 \pgfmathsetmacro{\xpx}{\xpx/\length} \pgfmathsetmacro{\ypy}{\ypy/\length} \pgfmathsetmacro{\zpz}{\zpz/\length} \pgfmathsetmacro{\pxppx}{\ppx-\px} \pgfmathsetmacro{\pyppy}{\ppy-\py} \pgfmathsetmacro{\pzppz}{\ppz-\pz} \tdplotcrossprod(\pxppx,\pyppy,\pzppz)(\xpx,\ypy,\zpz) \pgfmathsetmacro{\vx}{\vx+\tdplotresx/\length^2} \pgfmathsetmacro{\vy}{\vy+\tdplotresy/\length^2} \pgfmathsetmacro{\vz}{\vz+\tdplotresz/\length^2} \global\let\vx\vx \global\let\vy\vy \global\let\vz\vz \fi } \pgfmathsetmacro{\vl}{\fpeval{sqrt((\vx)^2+(\vy)^2+(\vz)^2)}} \pgfmathparse{\vl!=0} \ifnum\pgfmathresult=1 \draw[->] (\x,\y,\z) -- ++(0.2*\vx/\vl,0.2*\vy/\vl,0.2*\vz/\vl); \fi } } } \end{tikzpicture} \end{document} The output should be like this, but with more samples, and a bigger solenoid.
- How can I draw zig zag rectangle in TikZ? [closed]by ZaKW on February 5, 2025 at 8:45 am
I have to make a rectangle with two zig zag sides to make a diagram like this one: How can I do this?
- How to add arrows from one point on one plot to another point on second plot in tikz and pgfplotsby Mr.Price on February 4, 2025 at 2:57 pm
I have the following code to plot 3 lines from which 2 are just a translation of main plot 2 points up and down. I want to highlight that fact by adding arrows pointing up and down (of length 2 point) from middle plot to two other plots. How can I do that nicely in tikz and pgfplots without manually calculating the position of points on plot and adding/subtracting 2 from y coordinate? I would like to add these arrows every 20% of plot length (so 5 arrows in total). \documentclass[tikz, margin=3mm]{standalone} \usepackage{tikz} \usetikzlibrary{shapes, backgrounds, arrows.meta, fit,decorations.pathreplacing} \usepackage[dvipsnames]{xcolor} \usepackage{pgfplots} \usepgfplotslibrary{fillbetween} \pgfplotsset{compat=1.18} \usepackage{polski} \begin{document} \begin{tikzpicture}[ % show background grid, background grid/.style={thin, dotted, draw=gray,step=.5cm}, >=Stealth, remember picture, ] \begin{axis}[ xmin=-3.5, xmax=3.99, ymin=-4.5, ymax=4.99, xtick distance=1, ytick distance=1, xticklabels=\empty, yticklabels=\empty, extra y ticks={1}, % Dodatkowy tick na osi Y (dla b=1) extra y tick labels={$1$}, % Oznaczenie wartości b extra x ticks={1}, % Dodatkowy tick na osi Y (dla b=1) extra x tick labels={$1$}, % Oznaczenie axis lines=middle, % Osie przechodzą przez środek axis line style={-Stealth}, % Strzałki na osiach axis on top, % Osie na wierzchu xlabel={$X$}, % Oznaczenie osi X ylabel={$Y$}, % Oznaczenie osi Y xlabel style={at={(ticklabel* cs:1)}, anchor=north east}, % Pozycja etykiety X ylabel style={at={(ticklabel* cs:1)}, anchor=north west}, % Pozycja etykiety Y grid=both, % Dodaj siatkę grid style={dotted, gray!50}, % Styl siatki: kropkowana, szara set layers, % Włącz warstwy clip mode=individual, legend style={font=\tiny, scale=0.8, legend cell align=left}, legend pos=south west% Zmniejsza legendę ] \begin{pgfonlayer}{axis foreground} \addplot [domain=-3:3, samples=100, thick, color=Red] {x} node[pos=0.9, above] {\textbf{$\textcolor{Red}{f}$}}; \addplot [domain=-3:3, samples=100, thick, color=Orchid] {x+2} node[pos=0.9, above] {\textbf{$\textcolor{Orchid}{g}$}}; \addplot [domain=-3:3, samples=100, thick, color=Cerulean] {x-2} node[pos=0.9, above] {\textbf{$\textcolor{Cerulean}{h}$}}; \end{pgfonlayer} \end{axis} \end{tikzpicture} \end{document}
- Using Deployment Diagrams in Latex (using tikz or tikz-uml)by Stephan1403 on February 4, 2025 at 1:54 pm
For my bachelors thesis I wanted to include a Deployment Diagram. Something like this: For my other diagrams I found that using tikz-uml was the best. Unfortunately there seems to be no option to draw the 3d Boxes used in deployment diagrams with tikz-uml. What is the best way to include a deployment diagrams in my latex? P.s. this is my reference for tikz-uml: https://perso.ensta-paris.fr/~kielbasi/tikzuml/var/files/doc/tikzumlmanual.pdf
- TikZ Layers on custom codeby Emanuele Nardi on February 4, 2025 at 12:57 am
I'm working on adapting the code from How to Optimize a TikZ Animation of Quicksort? to use TikZ with layers. I want to add a layer that draws a rectangle with a very thick line. Additionally, I would like to include a line between the 7th and 8th elements, exactly in the middle of the vector. Furthermore, the labels should be positioned between the colored cells. More details are provided in the code. Desired output This is my current output: This is the output I would like to achieve: Code \documentclass[tikz, border=.2cm]{standalone} \usetikzlibrary{chains} % slide 11/52 \newcommand*\tikzqsset{\pgfqkeys{/tikz/qs}} \tikzqsset{ % default cell style vector/.style = {draw, shape=rectangle, minimum size = +0.7cm, outer sep = +0pt}, label/.style = {node distance = 0pt,font = \ttfamily\scriptsize}, % /tikz/label exists already % cells styles undiscovered/.style = {fill = white}, left/.style = {fill = red!30}, between/.style = {fill = yellow!30}, right/.style = {fill = blue!30}, % parsing style parse/.style args={#1#2}{qs/sc-#1/.try, node contents={#2}}, % defining styles sc-l/.style={in front of path, qs/undiscovered}, sc-L/.style={in front of path, qs/left}, sc-b/.style={in front of path, qs/between}, sc-r/.style={in front of path, qs/undiscovered}, sc-R/.style={in front of path, qs/right}, } \NewDocumentCommand{\DividiEtImpera}{ m }{ \tikz\path[node distance=+0pt, start chain=going right] { foreach[count=\i] \v in {#1}{ node[on chain, qs/vector, qs/parse/.expand once=\v] } } []; \tikz\draw[very thick] (chain-1.north west) rectangle (chain-16.south east); } \begin{document} \DividiEtImpera{l0, L1, L2, L3, L4, l5, b6, b7, b8, b9, b10, r11, r12, R13, R14, R15} % maxL label below and between 1 and 4 % maxRR label below and between 6 and 7 % maxLL label below and between 8 and 10 % maxR label below and between 13 and 15 \end{document}
- Draw Intervals using LaTeXby Averroes2 on February 3, 2025 at 7:33 pm
Does anyone has an idea how to draw this in LaTeX using TikZ: ChatGPT gave me this, but I cannot handle the arrows in order to correct it: \documentclass{article} \usepackage{tikz} \usepackage{amsmath} \usetikzlibrary{decorations.pathreplacing, positioning} \begin{document} \begin{center} \begin{tikzpicture} \draw[thick] (-6,0) -- (6,0); % Brackets \draw[decorate,decoration={brace,amplitude=6pt}] (-5.5,0.2) -- (-2.5,0.2) node[midway, above=4pt] {$k_L$}; \draw[decorate,decoration={brace,amplitude=6pt}] (-2.5,0.2) -- (-1,0.2) node[midway, above=4pt] {$i$}; \draw[decorate,decoration={brace,amplitude=6pt}] (-1,0.2) -- (1,0.2) node[midway, above=4pt] {$k_R$}; \draw[decorate,decoration={brace,amplitude=6pt}] (1,-0.4) -- (3,-0.4) node[midway, below=4pt] {$k_L'$}; \draw[decorate,decoration={brace,amplitude=6pt}] (3,-0.4) -- (5.5,-0.4) node[midway, below=4pt] {$k_R'$}; % Labels \node[above] at (-2.5,0) {$j$}; \node[above] at (3,0) {$j'$}; \node[below] at (-1,0) {$i$}; \node[below] at (1,0) {$i'$}; % Congruence Arrows \draw[dotted,->] (-2.5,0.3) to[out=60,in=120] (3,0.3) node[midway, above] {\textit{Cong}}; \draw[dotted,->] (-1,-0.5) to[out=-60,in=-120] (1,-0.5) node[midway, below] {\textit{Cong}}; \draw[dotted,->] (1,-0.6) to[out=-60,in=-120] (3,-0.6) node[midway, below] {\textit{Cong}}; \end{tikzpicture} \end{center} \end{document}
- tikz calendar in matrix produces "Undefined control sequence"by karu on February 3, 2025 at 3:08 pm
Code below fails with "Undefined control sequence" \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calendar,matrix} \begin{document} \begin{tikzpicture} \newcommand{\calmonth}[3]{\calendar[dates = #1-#2-1 to #1-#3-last, week list];} \matrix (tester) [matrix of nodes] { \calmonth{2025}{1}{1} & 3 \\ 2 & 4 \\ }; \end{tikzpicture} \end{document} It produces this error message: ! Undefined control sequence. \iterate ...til@tempcntb }\tikz@before@day \scope \tikz@atbegin@day \tikz@li... l.8 \calmonth{2025}{1}{1} & 3 \\ ? If \newcommand is put before \begin{document}, the error message stays the same. However this works fine \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calendar,matrix} \begin{document} \begin{tikzpicture} \newcommand{\punct}[3]{\fill[color = #1] (#2 mm, #2 mm) circle[radius = #3 mm];} \matrix (tester) [matrix of nodes] { \punct{red}{0}{0.5} & 3 \\ 2 & 4 \\ }; \end{tikzpicture} \end{document} and this as well \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calendar,matrix} \begin{document} \begin{tikzpicture} \newcommand{\calmonth}[3]{\calendar[dates = #1-#2-1 to #1-#3-last, week list];} \calmonth{2025}{1}{1} \end{tikzpicture} \end{document} There must be some deeper magic that I don't get.
- Setting node font size from withinby Cactus on February 3, 2025 at 12:18 pm
In the following example, I would like to set the font size of a node from "inside" the node's contents, i.e. without changing the node's font attribute: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} %% From https://tex.stackexchange.com/q/359189/2113 \def\gobblechar{\let\xchar= } \def\assignthencheck{\afterassignment\xloop\gobblechar} \def\xloop{% \ifx\relax\xchar \let\next=\relax \else \phantom{8}\makebox[0pt][r]{\xchar} \let\next=\assignthencheck \fi \next} \def\cellbits#1#2{\assignthencheck#1\relax \\ \assignthencheck#2\relax} \begin{scope}[scale=0.5,every node/.style={font=\large,align=center}] \draw[thin, densely dotted] (0,0) grid (7,1); \begin{scope}[shift={(0.5,0.5)}] \draw (0,0) node{1}; \draw (2,0) node{\cellbits{123}{456}}; \draw (4,0) node[font=\tiny]{\cellbits{123}{456}}; \draw (6,0) node{\tiny\cellbits{123}{456}}; \end{scope} \end{scope} \end{tikzpicture} \end{document} The nodes at (0,0) and (2,0) are just for reference. The node at (4,0) is exactly the output I would like to get. The node at (6,0) illustrates my problem. The \tiny size seems to be applied only to the first line (until the \\), and the line spacing and the second line all have size \large, i.e. the one based on the node's default font attribute: What can I put inside the (6,0) node's contents to get the same output as the (4,0) node? P.s.: If it can't be done "compositionally" i.e. if I have to change the definition of cellbits / xloop to "push in" the \tiny-ness, that is not optimal, but still fine.
- Adjusting vertical spacing and segment lengths in a tikz forest diagramby sidat on February 1, 2025 at 7:08 am
I am trying to use the tikz forest package to recreate the manually typeset diagram shown here: Here is my code thus far: \documentclass{standalone} \usepackage[edges]{forest} \forestset{ fairly nice empty nodes/.style={ delay={where content={} {shape=coordinate, for siblings={anchor=north}}{}}, for tree={s sep=4mm} }} \begin{document} \begin{forest} fairly nice empty nodes, for tree={ % style of tree (edges, distances, direction) grow = south, forked edge, % for forked edge s sep = 3mm, % "sibling" distance l sep = 4mm, % "level" distance fork sep = 3mm, % distance from parent to branching point align = center } [root [node 1 line 1\\node 1 line 2, calign=last [node 2 line 1\\node 2 line 2 [node 3]] [node 4 line 1\\node 4 line 2\\node 4 line 3\\node 4 line 4, calign=last [node 5] [node 6] [ [,l=10mm [node 7] [node 8] [node 9] [node 10] [node 11] [node 12] ] ] ] ] ] \end{forest} \end{document} It generates this tikz diagram: While it is close to the manually typeset version, there are some differences. Specifically, there are three areas of concern as noted on the tikz diagram. First, I would like to have less whitespace at the points shown in blue (between "root" and the line segment immediately below it, and between "node 2 line 2" and the line segment immediately below it. Second, I would like to lengthen the vertical line segments indicated by the green arrows so that they match the length of the corresponding segments above terminal nodes 7-12. Lastly, I would like to elongate the vertical segment highlighted in red (without altering the length of other segments). I used ",l=10mm" to elongate the segment above the terminal nodes, but that method doesn't appear to work for the red segment.
- unite and align nodes in tikzby Westlifer on January 21, 2025 at 6:03 am
I want to draw a tikzpicture like the above picture. I think I need to unite some nodes in the first row, then align corresponding nodes in the second row. But I don't know whether these are possible in a simple way in tikz. Any help would be appreciated! For example I tried this: \documentclass{article} \usepackage{tikz} \begin{document} \[ \begin{tikzpicture} \node (1) at (0,0) {$n$}; \node (2) at (1,0) {$n^r$}; \node (3) at (2,0) {$s$}; \node (4) at (3,0) {$n^l$}; \node (5) at (4,0) {$n$}; \node (6) at (5,0) {$s^r$}; \node (7) at (6,0) {$n^{rr}$}; \node (8) at (7,0) {$n^r$}; \node (9) at (8,0) {$s$}; \draw[out=-90,in=-90] (1.south) to (8.south); \draw[out=-90,in=-90] (2.south) to (7.south); \draw[out=-90,in=-90] (3.south) to (6.south); \draw[out=-90,in=-90] (4.south) to (5.south); \node[draw] (1a) at (0,1) {Bruce}; \node[draw] (2a) at (1,1) {put}; \node[draw] (3a) at (4,1) {his hat}; \node[draw] (4a) at (5,1) {on}; \draw (1a.south) to (1.north); \draw (2a.south) to (2.north); \draw (2a.south) to (3.north); \draw (2a.south) to (4.north); \draw (3a.south) to (5.north); \draw (4a.south) to (6.north); \draw (4a.south) to (7.north); \draw (4a.south) to (8.north); \draw (4a.south) to (9.north); \end{tikzpicture} \] \end{document} which yields Definitely not what I needed. To clarify: I need to connect those boxes with word to its corresponding letters ($n^r,s$...) like in the first picture, and properly aligned. The second picture is what I tried, I don't know how to connect properly, and let, say $n^r s n^l$, closer, aligned to the word 'put'
- Why does `datatool` fail when used in a Tikz figureby Rubem Pacelli on April 29, 2024 at 3:30 pm
Consider the following example \documentclass[varwidth=true, border=2pt]{standalone} \usepackage{tikz} \usepackage{pgfplots} \usepackage{datatool} \begin{filecontents*}[overwrite]{test.csv} Actual,Class 1,Class 2,Class 3 Class 1,1480.0,0.0,125.0 Class 2,112.0,1303.0,180.0 Class 3,174.0,95.0,1331.0 \end{filecontents*} \DTLloaddb[keys={Actual,Class 1,Class 2,Class 3}]% <options> {test}% <db name> {test.csv}% <filename> \newcommand{\fetchdata}[2]{\DTLfetch{test}{Actual}{Class #1}{Class #2}} \pgfplotsset{compat=1.17} \begin{document} Hi \fetchdata{1}{1} \begin{tikzpicture} \begin{axis}[ colormap={bluewhite}{color=(white) rgb255=(90,96,191)}, xlabel=Predicted, xlabel style={yshift=-30pt}, ylabel=Actual, ylabel style={yshift=20pt}, xticklabels={Class 1, Class 2, Class 3}, % changed xtick={0,...,2}, % changed xtick style={draw=none}, yticklabels={Class 1, Class 2, Class 3}, % changed ytick={0,...,2}, % changed ytick style={draw=none}, enlargelimits=false, colorbar, xticklabel style={ rotate=00 }, nodes near coords={\pgfmathprintnumber\pgfplotspointmeta}, nodes near coords style={ yshift=-7pt }, ] \addplot[ matrix plot, mesh/cols=3, % changed point meta=explicit, draw=gray ] table [meta=C] { x y C 0 0 0.5 1 0 0.01809 2 0 0.02366 0 1 0.05839 1 1 0.90109 2 1 0.01290 0 2 0.06525 1 2 0.08082 2 2 0.96344 }; % Add text in a specific position \node[anchor=south, yshift={-20pt}] at (axis cs:0,0) {(1531)}; \node[anchor=south, yshift={-20pt}] at (axis cs:1,0) {(30)}; \node[anchor=south, yshift={-20pt}] at (axis cs:2,0) {(33)}; \node[anchor=south, yshift={-20pt}] at (axis cs:0,1) {(102)}; \node[anchor=south, yshift={-20pt}] at (axis cs:1,1) {(1494)}; \node[anchor=south, yshift={-20pt}] at (axis cs:2,1) {(18)}; \node[anchor=south, yshift={-20pt}] at (axis cs:0,2) {(114)}; \node[anchor=south, yshift={-20pt}] at (axis cs:1,2) {(134)}; \node[anchor=south, yshift={-20pt}] at (axis cs:2,2) {(1344)}; \end{axis} \end{tikzpicture} \end{document} This produces However, If I try to put \DTLfetch inside the tikzpicture environment, that is: \documentclass[varwidth=true, border=2pt]{standalone} \usepackage{tikz} \usepackage{pgfplots} \usepackage{datatool} \begin{filecontents*}[overwrite]{test.csv} Actual,Class 1,Class 2,Class 3 Class 1,1480.0,0.0,125.0 Class 2,112.0,1303.0,180.0 Class 3,174.0,95.0,1331.0 \end{filecontents*} \DTLloaddb[keys={Actual,Class 1,Class 2,Class 3}]% <options> {test}% <db name> {test.csv}% <filename> \newcommand{\fetchdata}[2]{\DTLfetch{test}{Actual}{Class #1}{Class #2}} \pgfplotsset{compat=1.17} \begin{document} \begin{tikzpicture} \begin{axis}[ colormap={bluewhite}{color=(white) rgb255=(90,96,191)}, xlabel=Predicted, xlabel style={yshift=-30pt}, ylabel=Actual, ylabel style={yshift=20pt}, xticklabels={Class 1, Class 2, Class 3}, % changed xtick={0,...,2}, % changed xtick style={draw=none}, yticklabels={Class 1, Class 2, Class 3}, % changed ytick={0,...,2}, % changed ytick style={draw=none}, enlargelimits=false, colorbar, xticklabel style={ rotate=00 }, nodes near coords={\pgfmathprintnumber\pgfplotspointmeta}, nodes near coords style={ yshift=-7pt }, ] \addplot[ matrix plot, mesh/cols=3, % changed point meta=explicit, draw=gray ] table [meta=C] { x y C 0 0 0.5 1 0 0.\fetchdata{1}{1} 2 0 0.02366 0 1 0.05839 1 1 0.90109 2 1 0.01290 0 2 0.06525 1 2 0.08082 2 2 0.96344 }; % Add text in a specific position \node[anchor=south, yshift={-20pt}] at (axis cs:0,0) {(1531)}; \node[anchor=south, yshift={-20pt}] at (axis cs:1,0) {(30)}; \node[anchor=south, yshift={-20pt}] at (axis cs:2,0) {(33)}; \node[anchor=south, yshift={-20pt}] at (axis cs:0,1) {(102)}; \node[anchor=south, yshift={-20pt}] at (axis cs:1,1) {(1494)}; \node[anchor=south, yshift={-20pt}] at (axis cs:2,1) {(18)}; \node[anchor=south, yshift={-20pt}] at (axis cs:0,2) {(114)}; \node[anchor=south, yshift={-20pt}] at (axis cs:1,2) {(134)}; \node[anchor=south, yshift={-20pt}] at (axis cs:2,2) {(1344)}; \end{axis} \end{tikzpicture} \end{document} I get Undefined control sequence. \edtlgetrowforvalue ...def \@dtl@dogetrowforvalueLaTeX Undefined control sequence. \edtlgetrowforvalue ...#3}}\@dtl@dogetrowforvalueLaTeX Undefined control sequence. \dtlgetentryfromrow ...3->\edef \@dtl@do@getentryLaTeX Undefined control sequence. \dtlgetentryfromrow ...\the #3}}\@dtl@do@getentryLaTeX Undefined control sequence. \DTLfetch ...olumnindex {#1}{#4}}\dtlcurrentvalueLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing control sequence inserted. <inserted text>LaTeX Undefined control sequence. \dtlgetrowindex ...@ {#4}\edef \dtl@dogetrowindexLaTeX Undefined control sequence. \dtlgetrowindex ...he \toks@ }}\dtl@dogetrowindexLaTeX Undefined control sequence. \dtlgetrowforvalue ...lse \dtlrownum =\dtl@rowidxLaTeX Undefined control sequence. \dtlgetrowforvalue ...idx \relax \edef \dtldbnameLaTeX Missing \endcsname inserted. <to be read again>LaTeX Undefined control sequence. \dtlgetrowforvalue ...csname \edef \@dtl@dogetrowLaTeX Undefined control sequence. \dtlgetrowforvalue ... {\the \toks@ }{\dtl@rowidxLaTeX Undefined control sequence. \dtlgetrowforvalue ...dtl@rowidx }}\@dtl@dogetrowLaTeX Extra }, or forgotten \endgroup. \pgfmathresult ...romrow {\dtlcurrentvalue }{2}{}}LaTeX Undefined control sequence. \dtlgetrowindex ...he \toks@ }}\dtl@dogetrowindexLaTeX Undefined control sequence. \dtlgetrowforvalue ...lse \dtlrownum =\dtl@rowidxLaTeX Missing number, treated as zero. <to be read again>LaTeX Undefined control sequence. \dtlgetrowforvalue ...m =\dtl@rowidx \relax \edefLaTeX Undefined control sequence. \dtlgetrowforvalue ...idx \relax \edef \dtldbnameLaTeX Undefined control sequence. \dtlgetrowforvalue ...me dtldb@#1\endcsname \edefLaTeX Undefined control sequence. \dtlgetrowforvalue ...csname \edef \@dtl@dogetrowLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing { inserted. <to be read again>LaTeX Undefined control sequence. \dtlgetrowforvalue ...dtl@rowidx }}\@dtl@dogetrowLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Undefined control sequence. \GenericError ...LaTeX Undefined control sequence. \GenericError ...LaTeX Missing { inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing number, treated as zero. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \fi. \CheckEncodingSubset ...:\f@family \endcsname \fiLaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \else. \CheckEncodingSubset ...dafter \@firstoftwo \elseLaTeX Extra \fi. <recently read> \fiLaTeX Argument of \tc@subst has an extra }. <inserted text>LaTeX Paragraph ended before \tc@subst was complete. <to be read again>LaTeX Extra \fi. \GenericError ...rstchoice@ \else 6\fi \endcsnameLaTeX Extra \fi. \?-cmd ...ndcsname {\TextSymbolUnavailable #1}\fiLaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \fi. \?-cmd ...endcsname \csname ?\string #1\endcsnameLaTeX Extra \fi. \?-cmd ...sname \csname ?\string #1\endcsname \fiLaTeX Extra \else. \?-cmd ...\string #1\expandafter \endcsname \elseLaTeX Extra \fi. <recently read> \endcsnameLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \fi. <recently read> \endcsnameLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing number, treated as zero. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \else. \CheckEncodingSubset ...name #2:?\endcsname \elseLaTeX Extra \fi. \CheckEncodingSubset ...e #2:\f@family \endcsnameLaTeX Extra \fi. \CheckEncodingSubset ...:\f@family \endcsname \fiLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \else. \CheckEncodingSubset ...dafter \@firstoftwo \elseLaTeX Extra \fi. <recently read> \fiLaTeX Argument of \tc@subst has an extra }. <inserted text>LaTeX Paragraph ended before \tc@subst was complete. <to be read again>LaTeX Extra \fi. \GenericError ...rstchoice@ \else 6\fi \endcsnameLaTeX Extra \fi. \?-cmd ...ndcsname {\TextSymbolUnavailable #1}\fiLaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \fi. \?-cmd ...endcsname \csname ?\string #1\endcsnameLaTeX Extra \fi. \?-cmd ...sname \csname ?\string #1\endcsname \fiLaTeX Extra \else. \?-cmd ...\string #1\expandafter \endcsname \elseLaTeX Extra \fi. <recently read> \endcsnameLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \fi. <recently read> \endcsnameLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing number, treated as zero. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \else. \CheckEncodingSubset ...name #2:?\endcsname \elseLaTeX Extra \fi. \CheckEncodingSubset ...e #2:\f@family \endcsnameLaTeX Extra \fi. \CheckEncodingSubset ...:\f@family \endcsname \fiLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \else. \CheckEncodingSubset ...dafter \@firstoftwo \elseLaTeX Extra \fi. <recently read> \fiLaTeX Argument of \tc@subst has an extra }. <inserted text>LaTeX Paragraph ended before \tc@subst was complete. <to be read again>LaTeX Extra \fi. \GenericError ...rstchoice@ \else 6\fi \endcsnameLaTeX Extra \fi. \?-cmd ...ndcsname {\TextSymbolUnavailable #1}\fiLaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \fi. \?-cmd ...endcsname \csname ?\string #1\endcsnameLaTeX Extra \fi. \?-cmd ...sname \csname ?\string #1\endcsname \fiLaTeX Extra \else. \?-cmd ...\string #1\expandafter \endcsname \elseLaTeX Extra \fi. <recently read> \endcsnameLaTeX Missing \endcsname inserted. <to be read again>LaTeX Missing \endcsname inserted. <to be read again>LaTeX Extra \fi. <recently read> \endcsnameLaTeX Missing \endcsname inserted. <to be read again>LaTeX ==> Fatal error occurred, no output PDF file produced! Transcript written on main.log. Latexmk: Getting log file 'main.log' Latexmk: Examining 'main.fls' Latexmk: Examining 'main.log' Latexmk: Summary of warnings from last run of *latex:LaTeX That make not sense... Why \DTLfetch don't work as expected in `tikz picture?
- How to build the 3d cartesian coordinate system like this and add this graphby sukmudmaisus on March 31, 2024 at 5:42 pm
When I used the pgfplots or tikz3d I have a problem that the x,y,z axis doesn't like this. They always incline from it should be like the below image. How to set the x,y,z axis that x-axis is towards to the observer click to this link for information.
- Diagnosing Standalone and Gensymb conflictby Altissimo on January 9, 2024 at 5:52 pm
Disclaimer: I am new-ish to LaTeX, and self-taught. I am trying to make a "Unit Circle" TikZ graphic, in which I would like to have the \degree symbol from the gensymb package in the label text of a node. My current workflow involves the standalone package, and uses the \include command to create a sort of "master file" containing each of my creations on its own page which I reference in other Overleaf projects using the 'output file from another project' and the graphicx package to reduce compile time. There is probably a better way to do this, but it keeps it simple enough for me and I like having everything in more or less the same place so I can make quick references between my images. It has worked so far, until now... My problem is, it is preferable if I don't have to update the preamble of my master document every time I add a new picture, especially since that's where I define things like colors which occasionally use identical names (e.g. gradient1). Hence, I load \usepackage[subpreambles]{standalone} to read the preamble of each standalone separately. Again, this has worked well enough so far that I have been able to solve any hiccups myself. I have failed to diagnose why exactly, but there is something going on with the [subpreambles] tag and loading the gensymb package. Here is my MWE: \documentclass[tikz]{standalone} \usepackage{textcomp,gensymb} % for degree symbol \begin{document} \begin{tikzpicture} \node at (0,0) {$0\degree$}; \end{tikzpicture} \end{document} which I have in Overleaf as degree-test.tex. When I try to reference this file in another: \documentclass[tikz]{standalone} \usepackage[subpreambles]{standalone} \begin{document} \include{degree-test} \end{document} I get the error: Package standalone Warning: Sub-preamble of file 'degree-test.tex' has changed. Content will be ignored. Please rerun LaTeX! on input line 4. I compile with LuaLaTeX, but other compilers produce similar results. Even removing \degree from the node label produces the error, despite not actually using the symbol. There must be some kind of conflict with commands which define certain things during the preamble, but I don't know how to read the error logs and they're very frightening on the surface. Is there a simple fix for this? EDIT: I have also disqualified \documentclass[tikz]{standalone} and \include vs \includestandalone as culprits.
- Fancy Beamer presentation ToC: add a background Tikz pictureby cacamailg on November 18, 2023 at 12:52 pm
I want to have a fancy ToC in a Beamer presentation. For that, I want to have a the background filled with a certain color, or even with rounded edges. In the following code I have two approaches. The approach 1 does not work. The approach 2 does work. How can I make the approach 1 to work? I mean, without using Beamer-related features as \setbeamertemplate{background}? \documentclass{beamer} \usepackage{tikz} \usetikzlibrary{calc} \usetikzlibrary{fit} \usetikzlibrary{backgrounds} \defbeamertemplate*{section in toc}{tikz}{% \begin{tikzpicture}[remember picture,overlay] \global\let\theverylastsectionnumber=\inserttocsectionnumber \ifnum\inserttocsectionnumber>1 \pgfmathtruncatemacro\thelastsection{\inserttocsectionnumber-1} \node (tocnode\inserttocsectionnumber) [anchor=north east,inner sep=0pt] at ($(tocnode\thelastsection.south east)-(0pt,1ex)$) {\inserttocsection}; \else \node (tocnode1) [anchor=north east,inner sep=0pt] at (starttocnode) {\inserttocsection}; \fi \end{tikzpicture} } \begin{document} \makeatletter % Approach 1 does not works \begin{frame} \frametitle{\secname} \begin{tikzpicture}[remember picture,overlay] \coordinate[shift={(-\beamer@rightmargin,0pt)}] (starttocnode) at (current page.east); \end{tikzpicture} \tableofcontents \IfFileExists{\jobname.toc}{% \xdef\Loop{} \foreach \n in {1,...,\theverylastsectionnumber} {\xdef\Loop{\Loop(tocnode\n)}} \begin{tikzpicture}[remember picture,overlay] \begin{pgfonlayer}{background} \node (toc) [fill=-yellow!30!blue,fit=\Loop] {}; \end{pgfonlayer} \end{tikzpicture}% }{} \end{frame} % Approach 2 works \begingroup \setbeamertemplate{background}{% \IfFileExists{\jobname.toc}{% \xdef\Loop{} \foreach \n in {1,...,\theverylastsectionnumber} {\xdef\Loop{\Loop(tocnode\n)}} \begin{tikzpicture}[remember picture,overlay] \node (toc) [fill=-yellow!30!blue,fit=\Loop] {}; \end{tikzpicture}% }{} } \begin{frame} \frametitle{\secname} \begin{tikzpicture}[remember picture,overlay] \coordinate[shift={(-\beamer@rightmargin,0pt)}] (starttocnode) at (current page.east); \end{tikzpicture} \tableofcontents \end{frame} \endgroup \makeatother \section{Section test 1} \begin{frame}{\secname} \end{frame} \section{Section test 2} \begin{frame}{\secname} \end{frame} \end{document}
- Remove ticks from axes and draw arrows on arcsby SandyM on August 10, 2022 at 7:59 am
Question: Once you compile my codes, you will find the output like above pic. My question is whatever I made change manually with red color, How can I achieve that? Second question how to remove ticks from both axis and label both axis as X-axis and Y-axis. Thanks MWE: \documentclass[12pt]{article} \usepackage{pgf,tikz,pgfplots} \pgfplotsset{compat=1.15} \usepackage{mathrsfs} \usetikzlibrary{arrows} \usepgfplotslibrary{fillbetween} \pagestyle{empty} \usetikzlibrary{arrows,decorations.markings} \begin{document} \begin{center} \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm] \begin{axis}[ x=1cm,y=1cm, axis lines=middle, axis line style={stealth-stealth}, xmin=-7, xmax=7, ymin=-3, ymax=7, xticklabels=empty, yticklabels=empty] \draw [fill=black] (0,0) circle (3.5pt); \node [black] at (1,1) {$\circ$}; \node [black] at (2,1) {$\circ$}; \node [black] at (3,1) {$\circ$}; \node [black] at (4,1) {$\circ$}; \node [black] at (5,1) {$\circ$}; \node [black] at (1,2) {$\circ$}; \node [black] at (2,2) {$\circ$}; \node [black] at (3,2) {$\circ$}; \node [black] at (4,2) {$\circ$}; \node [black] at (5,2) {$\circ$}; \node [black] at (1,3) {$\circ$}; \node [black] at (2,3) {$\circ$}; \node [black] at (3,3) {$\circ$}; \node [black] at (4,3) {$\circ$}; \node [black] at (5,3) {$\circ$}; \node [black] at (-1,1) {$\circ$}; \node [black] at (-2,1) {$\circ$}; \node [black] at (-3,1) {$\circ$}; \node [black] at (-4,1) {$\circ$}; \node [black] at (-5,1) {$\circ$}; \node [black] at (-1,2) {$\circ$}; \node [black] at (-2,2) {$\circ$}; \node [black] at (-3,2) {$\circ$}; \node [black] at (-4,2) {$\circ$}; \node [black] at (-5,2) {$\circ$}; \node [black] at (-1,3) {$\circ$}; \node [black] at (-2,3) {$\circ$}; \node [black] at (-3,3) {$\circ$}; \node [black] at (-4,3) {$\circ$}; \node [black] at (-5,3) {$\circ$}; \draw [decoration={markings,mark=at position 1 with {\arrow[scale=2,>=stealth]{>}}},postaction={decorate}] (-1,-2) -- (-1,-1); \draw [decoration={markings,mark=at position 1 with {\arrow[scale=2,>=stealth]{>}}},postaction={decorate}] (-2,-2) -- (-2,-1); \draw [decoration={markings,mark=at position 1 with {\arrow[scale=2,>=stealth]{>}}},postaction={decorate}] (-3,-2) -- (-3,-1); \draw [decoration={markings,mark=at position 1 with {\arrow[scale=2,>=stealth]{>}}},postaction={decorate}] (1,-2) -- (1,-1); \draw [decoration={markings,mark=at position 1 with {\arrow[scale=2,>=stealth]{>}}},postaction={decorate}] (2,-2) -- (2,-1); \draw [decoration={markings,mark=at position 1 with {\arrow[scale=2,>=stealth]{>}}},postaction={decorate}] (3,-2) -- (3,-1); \draw[color=black] (2.0,-3) node[left,above] {$B_{0}$}; \draw[color=black] (-2.0,-3) node[left,above] {$B_{0}$}; \draw[color=black] (-5.5,-2) node[left,above] {$T_{w}$}; \draw[color=black] (-4.5,-2) node[left,above] {$C_{w}$}; \draw[color=black] (5.5,-2) node[left,above] {$C_{w}$}; \draw[color=black] (4.5,-2) node[left,above] {$T_{w}$}; \draw[color=black] (-5.5,6) node[left,above] {$T_{\infty}$}; \draw[color=black] (-4.5,6) node[left,above] {$C_{\infty}$}; \draw[color=black] (5.5,6) node[left,above] {$T_{\infty}$}; \draw[color=black] (4.5,6) node[left,above] {$C_{\infty}$}; \draw[color=black] (2.8,4) node[left,above] {$u_{e}(x)$}; \draw[color=black] (-2.8,4) node[left,above] {$u_{e}(x)$}; %%%%%%%%%%%%%%%%%%%%%%%%curve%%%%%%%%%%%%%%%%%%%%%%%% \draw (axis cs:1.0,7.0) to [bend right=35] coordinate[pos=0.2] (l_i) (axis cs:7,1.0); \draw (axis cs:0.7,7.0) to [bend right=35] coordinate[pos=0.2] (l_i) (axis cs:5,1.0); \draw (axis cs:0.5,7.0) to [bend right=35] coordinate[pos=0.2] (l_i) (axis cs:3,1.0); \draw (axis cs:-1.0,7.0) to [bend left=35] coordinate[pos=0.2] (l_i) (axis cs:-7,1.0); \draw (axis cs:-0.7,7.0) to [bend left=35] coordinate[pos=0.2] (l_i) (axis cs:-5,1.0); \draw (axis cs:-0.5,7.0) to [bend left=35] coordinate[pos=0.2] (l_i) (axis cs:-3,1.0); %%%%%%%%%%%%%%%%%%Rectangle%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \filldraw[fill=blue!20!white, draw=black] (-6,0) -- (-6,-0.1) -- (6,-0.1) -- (6,0) -- (-6,0); \draw[color=black] (1.8,0.2) node [right,above,rotate=00]{Stagnation Point}; \end{axis} \end{tikzpicture} \end{center} \end{document}
- Beamer footline weird interaction with ifnum and frame numberby Topa on May 26, 2021 at 9:24 am
I am creating a theme for a progressbar that shows for all slides except the first slide. I place the progressbar in the footline as I want it to show up at the bottom. What I don't understand is why this doesn't work (actually it shows a very tiny progressbar if you use zoom in a lot) \ifnum\insertframenumber>1\relax% %progress bar code \fi and this works \ifnum\insertframenumber=1\relax% \else %progress bar code \fi Another issue is that if I dont add \ifnum\inserttotalframenumber>1, it will fail on first run but works in subsequent runs. It seems that latex compiles the code twice in the first run with the first compilation having \inserttotalframenumber equal to 1 (causing division by 0). Is this correct? I put the code below. There is a comment for working code and not working code. It is compiled with Luatex. I am not sure if pdflatex will work. % filename: beamerouterthemetest.sty \mode<presentation> \RequirePackage{tikz} \newcount\progressbar@current \newcount\progressbar@total \newdimen\progressbar@curwidth \newdimen\progressbar@width \newdimen\progressbar@height \progressbar@width=\paperwidth \progressbar@height=1mm % the progress bar \def\progressbar@progressbar{% \progressbar@current=\insertframenumber \progressbar@total=\inserttotalframenumber \advance\progressbar@current-1 \advance\progressbar@total-1 \progressbar@curwidth=\progressbar@width \multiply\progressbar@curwidth by \progressbar@current \divide\progressbar@curwidth by \progressbar@total \begin{tikzpicture}[] \draw[fill=fg] % (0pt, 0pt) rectangle ++ (\progressbar@curwidth, \progressbar@height); \end{tikzpicture}% } % THIS WORKS!!!!!!!!!!!!!!!!!!! % Footline \defbeamertemplate*{footline}{test}[1][] { \ifnum\insertframenumber=1\relax% \else % Added next ifnum to avoid division by 0 crash in first run \ifnum\inserttotalframenumber>1\relax% \begin{beamercolorbox}[wd=\paperwidth]{progressbar}% \progressbar@progressbar% \end{beamercolorbox}% \fi \fi } % THIS DOESNT WORK!!!!!!!!!!!!!!!!!!! % % Footline % \defbeamertemplate*{footline}{test}[1][] { % \ifnum\insertframenumber>1\relax% % % Added next ifnum to avoid division by 0 crash in first run % \ifnum\inserttotalframenumber>1\relax% % \begin{beamercolorbox}[wd=\paperwidth]{progressbar}% % \progressbar@progressbar% % \end{beamercolorbox}% % \fi % \fi % } \mode<all> % filename: test-example.tex \documentclass[aspectratio=169]{beamer} \useoutertheme{test} \begin{document} \begin{frame}{Slide 1} \end{frame} \begin{frame}{Slide 2} \end{frame} \begin{frame}{Slide 3} \end{frame} \begin{frame}{Slide 4} \end{frame} \begin{frame}{Slide 5} \end{frame} \begin{frame}{Slide 6} \end{frame} \begin{frame}{Slide 7} \end{frame} \end{document}
- Placing anchor between two nodesby Ben on February 3, 2018 at 4:02 pm
I'm using tikzpicture to draw the next image: \begin{figure}[htbp] \centering \begin{tikzpicture} \draw[thick,->] (0,0) -- (6,0) node[anchor=north west] {x}; \draw[thick,->] (0,0) -- (0,6) node[anchor=south east] {y}; \fill (0.5,0.5) circle[radius=2pt]node[anchor=north west] {M}; \fill (5,4) circle[radius=2pt]node[anchor=north west] {T}; \fill (6,5) circle[radius=2pt]node[anchor=north west] {$D_{1}$}; \fill (4,3) circle[radius=2pt]node[anchor=north west] {$D_{2}$}; \draw[thick,->] (0.5,0.5) -- (1,1) node[anchor=north west] {$V_{M}$}; \draw[thick,->] (6,5) -- (5.5,5.5) node[anchor=north east] {$V_{T}$}; \draw[thick,->] (4,3) -- (3.5,3.5) node[anchor=north east] {$V_{T}$}; \draw[dashed,<->] (4,0.5) -- (4,2.9) node[-1cm] {$y_{T_{1}}$}; \draw[dashed,<->] (5,0.5) -- (5,3.9) node[anchor=south east] {$y_{cent}$}; \draw[dashed,<->] (6,0.5) -- (6,4.9) node[anchor=south east] {$y_{T_{2}}$}; \draw [dashed] (0.5,0.5) -- (6,0.5); \draw (6.414235,4) arc (0:360:1.414213); \end{tikzpicture} \end{figure} I would like the text of the middle line (y_{cent}) to appear where the red circle is and not in the top of the dashed arrow.
- Line Spacing: Align-Environment on Graph Paper (tikz)by Andreas Schneider on November 30, 2017 at 12:11 pm
I want to write some equations on graph paper generated by tikz. The problem I have is the line spacing in an equation environment. On left side of the following picture you see what I want. On the right side you see what I got. I don't understand why the line spacing is different. The right one should look like the left one. MWE \documentclass{scrartcl} \usepackage{amsmath} \usepackage{tikz} \begin{document} \begin{tikzpicture} % Graph Paper \draw[step=0.5,help lines,black!20] (-0.95,0.95) grid (15.95,-14.95); % Equation 1 \draw (0.5,0) node[below right] {\(y = 5 - 3x\)}; \draw (0.5,-1) node[below right] {\(y = 5 - 3x\)}; \draw (0.5,-2) node[below right] {\(y = 5 - 3x\)}; \draw (0.5,-3) node[below right] {\(y = 5 - 3x\)}; \draw (0.5,-4) node[below right] {\(y = 5 - 3x\)}; % Equation 2 \draw (0.5,0.65) node[below right] { \begin{minipage}{\linewidth} \begin{align*} y &= 5 - 3x\\[0.5cm] y &= 5 - 3x\\[0.5cm] y &= 5 - 3x\\[0.5cm] y &= 5 - 3x\\[0.5cm] y &= 5 - 3x \end{align*} \end{minipage} }; \end{tikzpicture} \end{document} Additional Information To use an align-environment in tikz you have to put it in a minipage-environment (https://tex.stackexchange.com/a/106813/101831).
- How to create an annuity timeline on LaTeXby Alexis Solis on April 29, 2015 at 5:10 am
I was wondering, how can I create a timeline exactly like this one: on LaTeX? I am a Finance student, and write all of my notes using LaTeX. These timelines, are giving me a headache. Since we use a lot of different timelines because of annuities. I want to learn how to create one basic timeline, so that I can then change anything I want. But basically, I want something like this, with the arrows and everything. Thank you so much guys!
- "Z-level" in TikZby Seamus on June 10, 2011 at 5:54 pm
This is an idle question, but neverthless, I think it's interesting. Does TikZ have a simple way to implement a "z-level" specification. By this, I don't mean 3D drawing, I mean specifying which parts of the picture are on top of what. So I'd write something like this: \draw[fill, blue,zlevel=1] (0,0) circle (2); \draw[fill,red,zlevel=2] (0,0) circle (1); and have the red circle appear on top of the blue one (since it has a higher z-level). I know I could just reverse the order, but I can imagine that being able to specify things this way round might make incremental changes to a TikZ picture in beamer easier by simplifying the overlay specifications... I suppose you could do something with remember picture, but it seems a "z-level" key would be the easiest solution (from the end user perspective). Is there anything like this? Is it possible?