TikZ
- Tikz comma shapeby Andrew on December 9, 2025 at 6:40 pm
I am using tikz to make a PA Dutch hex sign-like image. How can I make the comma-like shape that is seen below? I will ultimately be replicating it and rotating it around a center point, but I don't know how to get the basic shape to begin with.
- drawing arc using intersection with triangleby troy on December 9, 2025 at 5:26 pm
I've been trying to adapt the answer https://tex.stackexchange.com/a/239471 to the drawing I've been attempting, but I'm getting a strange result. I want draw an arc that begins and ends where it intersects with a triangle and spanning the interior of the triangle. My attempt at this is below. What I'm getting is a small, almond-shaped loop near one of the intersections. \documentclass[tikz]{standalone} \usepackage{pgfplots} \usetikzlibrary{fillbetween} \usetikzlibrary{3d} \usetikzlibrary{calc} \usetikzlibrary{intersections} \usetikzlibrary{perspective} \begin{document} \begin{tikzpicture}[scale=1.25, font=\sffamily] \pgfmathsetmacro{\alphasma}{1.4} \coordinate (O) at (0,0,0); \node at (O) {O}; \begin{scope}[scale=4,purple,very thick] \coordinate (X) at (0,0,1); \coordinate (Y) at (1,0,0); \draw[->] (O) -- (Y) node[anchor=north east]{\Large Y}; \draw[->] (O) -- (X) node[anchor=south]{\Large X}; \end{scope} \begin{scope}[3d view={90}{0.1}] \begin{scope}[scale=5,orange] \begin{scope}[rotate around y=20,black] \begin{scope}[rotate around z=-10,cyan] \begin{scope}[ canvas is xy plane at z=0, very thick ] \path[name path=lambdaArc] (O) circle [x radius=.95,y radius=.45]; \draw[name path=O-X-Y,dashed] (O) -- ($(O)!2*\alphasma!(X)$) -- ($(O)!2*\alphasma!(Y)$) -- cycle; \draw[red,thin, intersection segments={of=lambdaArc and O-X-Y,sequence=L3}]; \draw[orange,dashed] (O) circle [x radius=.95,y radius=.45]; \end{scope} \end{scope} \end{scope} \end{scope} \end{scope} \end{tikzpicture} \end{document} This is part of a larger diagram I am making. Deleting the extraneous parts leaves some scopes and structure that look unnecessary, but I left them as-is.
- How to distribute items (cards) evenly on a A4 page in Latex?by user32017992 on December 8, 2025 at 12:02 pm
I need to print cards (bussiness for example) on both sides of A4 paper so they must match exactly.I was trying to do some calculations and search for hidden margin, but none of those worked. code: https://github.com/moravechynek/latex_cards \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[english]{babel} \usepackage{graphicx} \graphicspath{{graphics/}} \usepackage{tikz} \usepackage{geometry} \geometry{margin=0mm} \setlength{\parindent}{0pt} % Card size (mm) \newcommand{\cardW}{63.5} \newcommand{\cardH}{88.9} % Gaps (mm): 4 gaps for 3 cards \newcommand{\gapX}{4.875} % (210 - 3*63.5) / 4 \newcommand{\gapY}{7.575} % (297 - 3*88.9) / 4 % A4 dimensions \newcommand{\Awidth}{210} \newcommand{\Aheight}{297} % Padding inside card \newcommand{\pad}{3} % FRONT CARD TEMPLATE \newcommand{\CardFront}[2]{% \begin{tikzpicture}[x=1mm, y=1mm] \useasboundingbox (0,0) rectangle (\cardW,\cardH); \draw[rounded corners=2mm, line width=0.3mm] (\pad,\pad) rectangle (\cardW-\pad,\cardH-\pad); \node[anchor=north,font=\LARGE] at (\cardW/2, \cardH-\pad-15) {#1}; \end{tikzpicture} } % BACK CARD TEMPLATE \newcommand{\CardBack}[1]{% \begin{tikzpicture}[x=1mm, y=1mm] \useasboundingbox (0,0) rectangle (\cardW,\cardH); \draw[rounded corners=2mm, line width=0.3mm] (\pad,\pad) rectangle (\cardW-\pad,\cardH-\pad); \node[anchor=north,font=\normalsize] at (\cardW/2, \cardH/1.4-\pad) {#1}; \end{tikzpicture} } \def\CardEntries{ 4 000, 4 800, 6 000, 8 000, 10 000, 12 000, 24 000, 16 000, 20 000 } \begin{document} \thispagestyle{empty} % FRONT SIDE (9 CARDS) \begin{tikzpicture}[x=1mm,y=1mm] \foreach [count=\idx from 0] \tl/\price in \CardEntries { \pgfmathtruncatemacro{\row}{floor(\idx/3)} \pgfmathtruncatemacro{\col}{\idx - 3*\row} \pgfmathsetmacro{\cx}{\gapX*(\col+1) + \cardW*\col + \cardW/2} \pgfmathsetmacro{\cy}{\Aheight - (\gapY*(\row+1) + \cardH*\row + \cardH/2)} \node at (\cx,\cy) {\CardFront{\tl}{\price}}; } \end{tikzpicture} \newpage \thispagestyle{empty} % BACK SIDE (9 CARDS) \begin{tikzpicture}[x=1mm,y=1mm] \foreach [count=\idx from 0] \tl/\price in \CardEntries { \pgfmathtruncatemacro{\row}{floor(\idx/3)} \pgfmathtruncatemacro{\col}{\idx - 3*\row} \pgfmathsetmacro{\cx}{\gapX*(\col+1) + \cardW*\col + \cardW/2} \pgfmathsetmacro{\cy}{\Aheight - (\gapY*(\row+1) + \cardH*\row + \cardH/2)} \node at (\cx,\cy) {\CardBack{Back}}; } \end{tikzpicture} \end{document}
- Drawing a sphere and ellipsoid togetherby Knudsen on December 8, 2025 at 4:00 am
I would like to draw a sphere, of radius 3, and an ellipsoid of semi-axis 2, 3 and 4 together. They intersect at two great circles on the sphere (marked in red). I started out with the sphere and the great circles: \documentclass[border=2mm]{standalone} \usepackage{tikz} \usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools \begin{document} \begin{tikzpicture}[3d/install view={phi=120,theta=70},line cap=butt, line join=round,declare function={R=3;},c/.style={circle,fill,inner sep=1pt}] \path (0,0,0) coordinate (O) ; \draw[blue,3d/screen coords] (O) circle[radius=R]; \shade[ball color=white,3d/screen coords,opacity=0.7] (O) circle[radius=R]; % \shade[ball color=blue!30,3d/screen coords,opacity=0.7,xscale=2,yscale=3,zscale=4] (O) circle[radius=1]; \path pic[blue]{3d/circle on sphere={R=R,C={(O)}}}; \path pic[red]{3d/circle on sphere={R=R, n={(0.592,0,-1)}}}; % plane x = sqrt{7/10) z \path pic[red]{3d/circle on sphere={R=R, n={(0.592,0,1)}}}; % plane x = sqrt{7/10) z \draw[3d/hidden] (0,0,0) -- (0,0,R) (O)--(R,0,0) (O)--(0,R,0) (O)--(0,-R,0); \draw[3d/visible, -stealth] (R,0,0) -- (R + 4,0,0) node[below]{$x$}; \draw[3d/visible, -stealth] (0,R,0) -- (0,R + 1,0) node[right]{$y$}; \draw[3d/visible, -stealth] (0,0,R) -- (0,0,R + 1.5) node[above]{$z$}; \end{tikzpicture} \end{document} and everything is right so far: but when I remove the comment on the line that I would expect to draw the ellipsoid \shade[ball color=blue!30,3d/screen coords,opacity=0.7,xscale=2,yscale=3,zscale=4] (O) circle[radius=1]; I get something that is far from what I expected, including the fact that the zscale is not understood. How can one add the intersecting elipsoide to this image?
- How to draw cone with infinitely many extremal raysby Fradns on December 6, 2025 at 10:21 am
Suppose we are working in the three-dimensional real vector space V. A cone is a subset C of V such that if an element v of V lies in C, then all of its nonnegative multiples also lie in C. I would like to draw, using TikZ, a cone that simulates infinitely many extremal rays, all accumulating toward a fixed one. A section of the cone should therefore look like a “polygon with infinitely many sides”. For example, the cone here Tikz: cones with a wide base is a circular one. I would like mine to be "polyhedral" away from the accumulation ray. How would you do that?
- TikZ: Generate a pixelated (Minecraft-style) circle by filling unit grid squares [duplicate]by Jax on December 6, 2025 at 8:35 am
I'm trying to draw a pixelated (blocky) circle in TikZ where each filled 1×1 square corresponds exactly to an integer grid cell (think Minecraft blocks). Given a center and radius, I want a compact TikZ/PGF macro or clear algorithm that selects which unit squares to fill so the rasterized shape matches a standard discrete circle (midpoint/Bresenham or distance-threshold) while preserving octant symmetry and avoiding visual gaps or doubled squares on diagonals. What is a simple, robust method to compute the set of grid cells for a given (integer or real) radius, and how can that be implemented cleanly in TikZ? Short macro examples, notes on rounding/aliasing pitfalls, and advice on scaling to a fixed cell size would be especially useful. For a quick visual reference I compared expected output with a pixel-circle preview online (pixel-circle preview).
- The method of marching cubes (for implicit surfaces) is very slow, and does not reach the level of accuracy of existing pictures. How to improve?by Jasper on December 6, 2025 at 5:58 am
I was inspired by some of the illustrations in https://math.stackexchange.com/a/46222. I wanted to try graphing implicit surfaces myself, and came across the method of marching cubes. See https://paulbourke.net/geometry/polygonise/. I collaborated with AI to produce the following code. If you are opposed to AI, this is your fair chance to recognize this fact and not participate in answering this question. It is extremely slow for many subdivisions, and unfortunately, I need many subdivisions to even remotely approach the desired graphic. The desired graphic is something like this: I would very much like for my attempt to be almost isomorphic (same shape) to the original picture. I cut out a large portion of occlusion code to get this to run in my lifetime. I hope to use far less triangles, and for it to adapt to regions of high and low density if possible. One idea I had was to take an initial coarse subdivision set, then up the samples in regions where the surface was not found up to a maximum depth. Then we could only sample highly where it is needed. This is just speculation though, and sounds very difficult to achieve. Obviously the desired technology exists currently, because of the desired picture's existence. MWE: \documentclass[tikz,border=3mm]{standalone} \usepackage{luacode} \begin{document} % Run LuaTeX code to generate the triangles \begin{luacode*} -- Parameters local nx, ny, nz = 80, 80, 80 -- grid resolution local x0, y0, z0 = -1, -1, -1 local x1, y1, z1 = 1, 1, 1 local isovalue = 0.0 local dx = (x1-x0)/nx local dy = (y1-y0)/ny local dz = (z1-z0)/nz -- Scalar function local function f(u, v, w) return (2.92*(u-1)*u*u*(u+1) + 1.7*v*v)^2 * ((v*v - 0.88)^2) + (2.92*(v-1)*v*v*(v+1) + 1.7*w*w)^2 * ((w*w - 0.88)^2) + (2.92*(w-1)*w*w*(w+1) + 1.7*u*u)^2 * ((u*u - 0.88)^2) - 0.02 end -- On-demand vertex value local function vertex_value(i,j,k) return f(x0 + i*dx, y0 + j*dy, z0 + k*dz) end -- Edge bisection local function edge_root(p0,p1,v0,v1,tol) local a,b = 0,1 local fa,fb = v0,v1 for iter=1,20 do local m = 0.5*(a+b) local pm = { x = p0.x + m*(p1.x-p0.x), y = p0.y + m*(p1.y-p0.y), z = p0.z + m*(p1.z-p0.z) } local fm = f(pm.x, pm.y, pm.z) if math.abs(fm)<tol then return pm end if fa*fm<=0 then b,fb = m,fm else a,fa = m,fm end end return {x=p0.x+0.5*(p1.x-p0.x), y=p0.y+0.5*(p1.y-p0.y), z=p0.z+0.5*(p1.z-p0.z)} end -- Minimal demo marching cubes table -- https://paulbourke.net/geometry/polygonise/ local raw_table = {{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1}, {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1}, {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1}, {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1}, {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1}, {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1}, {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1}, {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1}, {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1}, {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1}, {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1}, {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1}, {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1}, {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1}, {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1}, {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1}, {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1}, {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1}, {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1}, {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1}, {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1}, {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1}, {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1}, {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1}, {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1}, {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1}, {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1}, {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1}, {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1}, {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1}, {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1}, {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1}, {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1}, {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1}, {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1}, {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1}, {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1}, {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1}, {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1}, {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1}, {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1}, {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1}, {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1}, {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1}, {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1}, {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1}, {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1}, {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1}, {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1}, {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1}, {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1}, {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1}, {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1}, {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1}, {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1}, {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1}, {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1}, {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1}, {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1}, {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1}, {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1}, {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1}, {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1}, {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1}, {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1}, {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1}, {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1}, {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1}, {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1}, {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1}, {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1}, {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1}, {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1}, {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1}, {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1}, {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1}, {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1}, {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1}, {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1}, {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1}, {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1}, {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1}, {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1}, {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1}, {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1}, {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1}, {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1}, {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1}, {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1}, {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1}, {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1}, {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1}, {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1}, {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1}, {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1}, {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1}, {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1}, {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1}, {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1}, {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1}, {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1}, {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1}, {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1}, {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1}, {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1}, {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1}, {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1}, {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1}, {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1}, {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1}, {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1}, {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1}, {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1}, {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1}, {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1}, {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1}, {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1}, {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1}, {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1}, {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1}, {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1}, {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1}, {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1}, {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1}, {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1}, {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1}, {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1}, {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1}, {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1}, {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1}, {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1}, {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1}, {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1}, {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1}, {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1}, {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1}, {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1}, {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1}, {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1}, {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1}, {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1}, {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1}, {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1}, {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1}, {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1}, {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1}, {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1}, {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1}, {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1}, {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1}, {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1}, {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1}, {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1}, {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1}, {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1}, {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1}, {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1}, {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1}, {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1}, {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1}, {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1}, {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1}, {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1}, {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1}, {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1}, {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1}, {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1}, {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1}, {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1}, {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1}, {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1}, {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1}, {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1}, {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1}, {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1}, {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1}, {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1}, {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1}, {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1}, {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}} -- Convert raw_table to marching_cubes_table (list of triangles per config) local triTable = {} for idx, entry in ipairs(raw_table) do local triangles = {} local i = 1 while entry[i] ~= -1 do if entry[i+2] ~= -1 then table.insert(triangles, {entry[i], entry[i+1], entry[i+2]}) i = i + 3 else break end end triTable[idx] = triangles -- 1-based end -- Edge to corners mapping (1-based) local edge_to_corners = { {1,2},{2,3},{3,4},{4,1}, {5,6},{6,7},{7,8},{8,5}, {1,5},{2,6},{3,7},{4,8} } -- Corner offsets and edges local cornerOffsets = {{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,0,1},{1,0,1},{1,1,1},{0,1,1}} local edgeIndex = {{1,2},{2,3},{3,4},{4,1},{5,6},{6,7},{7,8},{8,5},{1,5},{2,6},{3,7},{4,8}} -- Preallocated triangle points local pts = {{},{},{}} -- Open output file local f = io.open("triangles.tex","w") f:write([[ \documentclass[tikz,border=3mm]{standalone} \begin{document} \begin{tikzpicture} ]]) -- Main loop for i=0,nx-1 do for j=0,ny-1 do for k=0,nz-1 do -- corner values on-demand local cubeVals = {} for ci=1,8 do local ox,oy,oz = cornerOffsets[ci][1], cornerOffsets[ci][2], cornerOffsets[ci][3] cubeVals[ci] = vertex_value(i+ox,j+oy,k+oz) end -- cube index local cubeIndex = 0 for ci=1,8 do if cubeVals[ci]<isovalue then cubeIndex = cubeIndex + 2^(ci-1) end end if cubeIndex ~=1 and cubeIndex ~=256 then local x = x0 + i*dx local y = y0 + j*dy local z = z0 + k*dz -- corner positions local p = {} for ci=1,8 do p[ci] = {x=x+cornerOffsets[ci][1]*dx, y=y+cornerOffsets[ci][2]*dy, z=z+cornerOffsets[ci][3]*dz} end -- triangles -- triangles for _, tri in ipairs(triTable[cubeIndex+1] or {}) do for ei=1,3 do local e = tri[ei] local c1,c2 = edgeIndex[e+1][1], edgeIndex[e+1][2] local v1,v2 = cubeVals[c1], cubeVals[c2] local pos = edge_root(p[c1],p[c2],v1,v2,1e-6) pts[ei].x = pos.x pts[ei].y = pos.y pts[ei].z = pos.z -- <--- THIS LINE IS MISSING end f:write(string.format([[\draw[fill=blue!20,draw=blue!60,line join = round, ultra thin] (%.5f,%.5f,%.5f) -- (%.5f,%.5f,%.5f) -- (%.5f,%.5f,%.5f) -- cycle; ]], pts[1].x, pts[1].y, pts[1].z, pts[2].x, pts[2].y, pts[2].z, pts[3].x, pts[3].y, pts[3].z)) end end end end end f:write([[\end{tikzpicture}\end{document}]]) f:close() \end{luacode*} \end{document}
- TikZ word search diagram v2by yannis on December 4, 2025 at 7:16 pm
As a continuation of TikZ word search diagram here is the problem I'm facing. I did what Explorer suggested and it worked fine except that my rounded rectangles look like sausages or like Hieroglyphic cartouches because at their narrow ends they have lines on the secondary axis: Here is the code: \documentclass{article} \usepackage[cmyk]{xcolor} \definecolor{myPB}{cmyk}{0.85,0.75,0,0} \definecolor{myLB}{cmyk}{0.1,0.06,0,0} \usepackage{tikz} \usetikzlibrary{matrix,backgrounds} \newlength{\mydrawlinewidth} \setlength{\mydrawlinewidth}{1pt} \NewDocumentCommand{\markA}{ O{red} m m }{% \draw[rounded corners=6mm,opacity=.5, line width=2pt,myPB,fill=myLB] ([xshift=5pt,yshift=-5pt]yannis-#2.north west) rectangle ([xshift=-5pt,yshift=5pt]yannis-#3.south east); } \NewDocumentCommand{\markB}{ O{red} m m }{% \draw[rounded corners=6mm,opacity=.5,line width=2pt,myPB,fill=myLB] ([yshift=2pt]yannis-#2.north) -- ([xshift=2pt]yannis-#3.east) -- ([yshift=-2pt]yannis-#3.south) -- ([xshift=-2pt]yannis-#2.west) -- cycle; } \NewDocumentCommand{\markC}{ O{red} m m }{% \draw[rounded corners=6mm,opacity=.5,line width=2pt,myPB,fill=myLB] ([xshift=2pt]yannis-#2.east) -- ([yshift=-2pt]yannis-#3.south) -- ([xshift=-2pt]yannis-#3.west) -- ([yshift=2pt]yannis-#2.north) -- cycle; } \begin{document} \begin{tikzpicture} \matrix (yannis) [% matrix of nodes,% column sep=0mm,% row sep=0mm, nodes={ % draw, rectangle,anchor=center, line width=0.5pt, inner sep=2pt,outer sep=0pt, %font=\bfseries\huge, minimum size=1.1cm, } ] { S & G & A & Q & Q & T & C & E & F & R & E & P & Y & W & R \\ W & L & Q & E & L & B & A & R & A & P & M & O & C & E & L \\ Y & I & T & S & X & E & L & I & Y & A & H & U & W & R & A \\ B & K & E & E & Y & C & W & L & J & T & M & A & K & B & F \\ J & E & R & I & O & R & T & M & K & E & R & L & Q & E & T \\ P & N & P & L & S & B & R & W & H & D & U & U & E & H & E \\ E & E & R & R & E & W & V & S & S & M & L & N & K & E & R \\ H & S & E & E & H & T & A & P & H & Y & S & I & C & A & L \\ S & S & T & D & S & H & E & U & Q & V & L & V & R & Z & I \\ O & R & N & N & I & F & L & L & A & S & N & E & E & K & F \\ M & T & I & U & N & L & G & E & P & H & U & R & A & S & E \\ W & K & O & Q & U & P & U & H & A & M & G & S & T & M & I \\ A & F & A & R & P & J & M & S & L & R & O & E & E & H & C \\ B & X & H & C & A & I & H & S & A & M & S & C & D & F & G \\ I & P & R & O & P & H & E & T & S & N & S & I & F & X & Q \\ }; \begin{scope}[on background layer] \markA{1-6}{1-12} \markA{1-14}{6-14} \markC{1-15}{7-9} \markA{2-2}{9-2} \markA{2-4}{2-13} \markA{3-3}{11-3} \markA{3-4}{11-4} \markA{3-6}{3-12} \markA{3-15}{11-15} \markC{4-11}{9-6} \markA{6-5}{13-5} \markA{6-12}{13-12} \markA{7-1}{11-1} \markB{7-5}{14-12} \markA{8-8}{8-15} \markA{8-13}{14-13} \markB{10-7}{15-12} \markB{11-2}{15-6} \markA{14-3}{14-10} \markA{15-2}{15-9} \end{scope} \end{tikzpicture} \end{document} How can I fix this? @mickep I replaced the snippets by a complete minimal example.
- I would like to discretize the "tiles" into rectangular prismatic groups, sort each group, then sort the groups by each other or be shown a better wayby Jasper on December 4, 2025 at 7:58 am
I have built a comparator which can determine the occlusive relationship between two 0--2-dimensioal affine tiles (using their simplicial representations). In English, if I have two tiles (a tile is a point, line segment, or triangle), I can determining which one occludes the other, or if there is no occlusion (the inconclusive case). Currently, this requires an extremely expensive SCC topological sort (quadratic based on the number of tiles). I have the idea that I would like to speed this up, and I have a proposal for doing so (though, I am all ears to alternative ideas too). Basically, my idea is to partition the scene into rectangular prismatic regions (possibly with some overlap), sorting each one individually. Then, each rectangular prismatic region could use a waaay simpler sorting method on the set of rectangular prismatic region, once their constituent parts are sorted. This is my AI generated SCC topological sort routine, which has been working for ages. I am confident in it, based on it having not failed yet. How could I go about implementing this without visual artefacts from tiles which cross the boundary of two or more prisms? Alternatively, what better methods might I consider which I haven't yet? -- occlusion graph + SCC topo sort (bboxes computed on Cartesian coords) local n = #items local bboxes, graph = {}, {} for i = 1, n do bboxes[i] = { get_bbox2(items[i]) }; graph[i] = {} end for i = 1, n - 1 do for j = i + 1, n do if bboxes_overlap2(bboxes[i], bboxes[j]) then local r = cmp(items[i], items[j]) if r == true then table.insert(graph[i], j) elseif r == false then table.insert(graph[j], i) end end end end local index, stack, indices, lowlink, onstack, sccs = 0, {}, {}, {}, {}, {} for i = 1, n do indices[i], lowlink[i] = -1, -1 end local function dfs(v) indices[v], lowlink[v] = index, index; index = index + 1 stack[#stack+1] = v; onstack[v] = true for _, w in ipairs(graph[v]) do if indices[w] == -1 then dfs(w); lowlink[v] = math.min(lowlink[v], lowlink[w]) elseif onstack[w] then lowlink[v] = math.min(lowlink[v], indices[w]) end end if lowlink[v] == indices[v] then local scc = {} while true do local w = table.remove(stack); onstack[w] = false scc[#scc+1] = w if w == v then break end end sccs[#sccs+1] = scc end end for v = 1, n do if indices[v] == -1 then dfs(v) end end local scc_index, scc_graph, indeg = {}, {}, {} for i, comp in ipairs(sccs) do for _, v in ipairs(comp) do scc_index[v] = i end scc_graph[i], indeg[i] = {}, 0 end for v = 1, n do for _, w in ipairs(graph[v]) do local si, sj = scc_index[v], scc_index[w] if si ~= sj then table.insert(scc_graph[si], sj); indeg[sj] = indeg[sj] + 1 end end end local queue, sorted = {}, {} for i = 1, #sccs do if indeg[i] == 0 then queue[#queue+1] = i end end while #queue > 0 do local i = table.remove(queue, 1) for _, v in ipairs(sccs[i]) do sorted[#sorted+1] = items[v] end for _, j in ipairs(scc_graph[i]) do indeg[j] = indeg[j] - 1 if indeg[j] == 0 then queue[#queue+1] = j end end end In fact, I would also like to employ a similar strategy for partitioning, since it is also quadratic, but I think that if I saw it for occlusion, that it would be simple to re-implement for partitioning. This MWE, for example, takes ages to compile, and I believe it should be speed-up-able. This version is currently on TeXLive and MikTeX (and on CTAN), so there is no need to use the GitHub version. \documentclass[tikz,border=1cm]{standalone} \usepackage{lua-tikz3dtools} % https://github.com/Pseudonym321/TikZ-Animations/tree/master1/TikZ/lua-tikz3dtools \begin{document} \begin{luatikztdtoolspicture}[ C1 = { {{-3,-3,0,1}} } ,C2 = { {{3,3,-10,1}} } ,light = { {{0,0,-2,1}} } ] \pgfmathsetmacro{\param}{0} \setobject[ name = {T} ,object = { matrix_multiply( matrix_multiply( euler(pi/2,pi/4+pi/4*sin(\param),5.25*pi/6+\param) ,translate(0,0,-5) ) ,matrix_multiply( { {1,0,0,0} ,{0,1,0,0} ,{0,0,1,0} ,{0,0,0,1} } ,matrix_multiply(xscale(1/2),yscale(1/2)) ) ) } ] \setobject[ name = {I} ,object = { matrix_inverse(T) } ] \appendsurface[ ustart = {-2} ,ustop = {2} ,usamples = {20} ,vstart = {-2} ,vstop = {2} ,vsamples = {20} ,transformation = {T} ,x = {u} ,y = {v} ,z = {u^4 + v^4 - 4*u*v + 1} ,fill options = { preaction = { fill = green ,fill opacity = 0.2 } ,postaction = { draw = blue ,ultra thin ,line join = round } } ,filter = { abs(matrix_multiply(A,I)[1][3])<2.01 and abs(matrix_multiply(B,I)[1][3])<2.01 and abs(matrix_multiply(C,I)[1][3])<2.01 and abs(matrix_multiply(A,I)[1][2])<2.01 and abs(matrix_multiply(B,I)[1][2])<2.01 and abs(matrix_multiply(C,I)[1][2])<2.01 and abs(matrix_multiply(A,I)[1][1])<2.01 and abs(matrix_multiply(B,I)[1][1])<2.01 and abs(matrix_multiply(C,I)[1][1])<2.01 } ] \appendsolid[ ustart = {-2} ,ustop = {2} ,usamples = {2} ,vstart = {-2} ,vstop = {2} ,vsamples = {2} ,wstart = {-2} ,wstop = {2} ,wsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {w} ,fill options = { preaction = { fill = none ,fill opacity = 0.5 } ,postaction = { draw = none ,ultra thin ,line join = round ,line cap = round } } ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {0} ,y = {0} ,z = {u} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {0} ,y = {0} ,z = {4.3} ,transformation = {T} ,name = {\(z\)} ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {0} ,y = {u} ,z = {0} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {0} ,y = {4.3} ,z = {0} ,transformation = {T} ,name = {\(y\)} ] \appendcurve[ ustart = {0} ,ustop = {4} ,usamples = {2} ,x = {u} ,y = {0} ,z = {0} ,transformation = {T} ,arrow tip = {true} ,draw options = { draw ,ultra thin ,line cap = round } ] \appendlabel[ x = {4.3} ,y = {0} ,z = {0} ,transformation = {T} ,name = {\(x\)} ] \foreach \p in {-4,-3,...,4} { \appendcurve[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,x = {u} ,y = {\p} ,z = {0} ,transformation = {T} ,draw options = { draw = black!70!white ,ultra thin ,line cap = round ,densely dashed } ] \appendcurve[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,x = {\p} ,y = {u} ,z = {0} ,transformation = {T} ,draw options = { draw = black!90!white ,ultra thin ,line cap = round ,densely dashed } ] } \appendsurface[ ustart = {-4} ,ustop = {4} ,usamples = {2} ,vstart = {-4} ,vstop = {4} ,vsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {0} ,fill options = { preaction = { fill = gray!70!white ,fill opacity = 0.6 } ,postaction = { draw = none ,ultra thin ,line join = round } } ] \end{luatikztdtoolspicture} \end{document}
- Is there a way in TikZ or Lua to make a short function which converts letters to their corresponding alphabetical position (and vice versa)?by Jasper on December 2, 2025 at 5:38 pm
Is there a way in TikZ or Lua to make a short function which converts letters to their corresponding alphabetical position (and vice versa)? The only way I can think of it so string check each letter, but that sounds too computationally expensive. M(non)WE: \documentclass[tikz,border=1cm]{standalone} \newcommand{\letterpos}[1]{ \pgfmathparse{#1 == a} \ifnum\pgfmathresult=1 1 \fi \pgfmathparse{#1 == ab} \ifnum\pgfmathresult=1 2 \fi \pgfmathparse{#1 == c} \ifnum\pgfmathresult=1 3 \fi \pgfmathparse{#1 == d} \ifnum\pgfmathresult=1 4 \fi \pgfmathparse{#1 == e} \ifnum\pgfmathresult=1 5 \fi } \begin{document} \begin{tikzpicture} \foreach \letter in {a,b,...,e} { \node at (\letterpos{\letter},0) {\letter}; } \end{tikzpicture} \end{document}
- tikz node fill to highlight text causes extra line below text (used in tblr)by bennynihon on November 29, 2025 at 5:58 am
When I use the text highlighting tikz command, as shared here, it adds an extra line or vertical spacing below it. In my case I'm using it in a two column nested tblr. You can see if the tikz highlight is replaced with a simple bold text, it works as expected with no extra vertical space. I thought it was the size of the highlight creating the issue, so I tried an 'inner sep=1pt' in the tikz command, but it still results in the extra space. How can I avoid this extra space below? Thank you. \documentclass{article} \usepackage{tabularray} \usepackage{tikz} \definecolor{mblue}{HTML}{2a66ad} \newcommand{\hlitet}[2][mblue]{% \hspace{0pt}{% \tikz[baseline=(N.base)]\node[fill=#1,rounded corners](N){#2}; }% \hspace{-2pt}% } % using hlines and vlines to show the effect \NewDocumentCommand{\fsmtx}{mm}{% \begin{tblr}{colspec={@{}X[l,-1]@{\hspace{4pt}}X[l]@{}},baseline={T},hlines,vlines}% {\hlitet[mblue]{\textcolor{white}{#1}}} & {#2}% \end{tblr}% } \NewDocumentCommand{\fsmtxb}{mm}{% \begin{tblr}{colspec={@{}X[l,-1]@{\hspace{4pt}}X[l]@{}},baseline={T},hlines,vlines}% {\textcolor{mblue}{\textbf{#1.}}} & {#2}% \end{tblr}% } \begin{document} \begin{longtblr}{ colspec={X[l,-1]X[l,-1]}, rowhead=1, hlines,vlines } {State} & {Transitions} \\ {StateA} & \fsmtx{a}{this is a test of a single line description} \fsmtx{b}{this is a test of a multi line description, as this will occupy a second line} \\ {StateB} & \fsmtxb{a}{this is a test of a single line description} \fsmtxb{b}{this is a test of a multi line description, as this will occupy a second line} \end{longtblr} \end{document} Update: swapping the \hlitet with this tcbox solution below, seems to work well. But I am curious as to why the tikz solution causes the additional vertical spacing. \newcommand\hliteb[2][mblue]{\tcbox[on line, colback=#1, colframe=#1, boxsep=0pt, top=3pt, bottom=3pt, left=3pt, right=3pt, boxrule=0pt]{#2}}
- Using ASCII Art & pxpicby Sebastiano on November 28, 2025 at 9:30 pm
With https://www.asciiart.eu/ ASCII Art Archive I wanted to create the same dragon of the mame game: Black Tiger, At the moment, I haven’t understood how to use the options inside \pxpic[...], or which ones to set in the package so that it can correctly recognise the colours of the dragon image. \documentclass[border=3.14]{standalone} \usepackage{pxpic} \begin{document} \pxpic[.......] { -:- ++======++ +++==+++ -:- +=---.....-..:--.:--=++ %*+#%@%%#+==-==++ ++-=++- ##### +==-::::-=+*#%@@%%@@@%%###**+====+ ++#@+%#*@%@+=-==+-- +=*@@-=*:++*+- #=.....:--*=:--::----=%@@%*+##*+*@#*=*@%*+*%@***@@*+ ++%*%*%#@##=+==::===*++:-+#*@%*-+ +*# #++::==.:=====+%@##%*+#%*=*%*++%#*+*%**++* *%*%*#*@%@*+++%###%*--+#%%%%*- #*=:-===-:-+-:=+###@@%#%%++%#*+#%*+* +*%*%%#@#=+=+**+*=--**@@#%#* **# #+====---=+======---:::-=+*%@#+#%*++* *@#%%+==*@@**%*-:=--*%#@#** ##=::..=-+-+**==-=+@##%**#@@@@%+=-+%@%*+ @%*#*%%*#%%#+=-*%%.+#+=**+#* +=+-:=#*%@@@%--+%*%*+%%**#%%@@%#+*% %*#%+#@%#*%=:*@@*+%=@+#-*#+++#**# +-:=%##+*#@@@@+-+%#%**@**+* *# ## **%@##@%%@#*+*#--==*#++++*## ###*#*=-*###%*+*%%%%%+-*###** ##@%%%*%@*++%##%@+**++****+=###+++==+-==%@#%+%#**%%##%@+=## %# **#@#@@*+=+*+#%**=#+-=@+=*==*==*++*=+@*%*#%*+** @+=* %%@@%#@%%@#++**@*+#+=+@*++%##%%%%%%%+=##%#* ** ##+#++@=#@*--=*@#+-+@#+*@#@#+#@@**%@%+*@* ##**#*@#*@#*@****+*%*##++=##@*%**%%*+** ## #*@%## *=-=+*%*@+**==-+%#%#* #%# *++++=%#=#+=:*-*%*** ###@*+=+*%#%---+--*@@ *#*+#%+--=%+:+++**#:**# @*+#*%****%**-+#####**+* #**%**##**+*@#%%#**##**#%#* #* *##*#* %%%**#%##%**## ##@****##+#*++@###*#**#*+*####*####*### ##+%@*++#+*@# #*#+####%%#*#+=**+#++#++#*+##+*######*## ****## #**:+#*=*#*#%##**++#****#**## ###*###*##*#*# %## ##% #+-#++=***@@ ## %## * +## #+# } \end{document}
- Circuitikz: customize the style of the rotary switch position displayby cis on November 27, 2025 at 8:54 pm
I've been experimenting with a rotary switch. I want 7 switch positions with a gap at the bottom. My question is: can the thick black line be replaced with a nice arrow? By the way: it seems exceptionally difficult to set the switch to a specific position (1, 2, ..., 7). My method of calculating the angle \s works, but if there's an easier way, please let me know. \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage[]{circuitikz} \def\S{5}% switch position 1,2,...,7; 7=\N \pgfmathsetmacro\s{-2*(\S+4)*180/8}% switch angle <-- I do not know a easier methode \def\No{7}% number of switch positons \pgfmathsetmacro\RSangle{6*180/8}% complete angle of the rotary switch <-- seems to be good \begin{document} \begin{circuitikz} \draw (0,0) node[rotary switch=\No in \RSangle wiper \s, rotate=90, ](S){}; \foreach \i in {1,...,\No}{%% requires "calc" \path[] ($(S.aout \i)!1ex!(S.sqout \i)$) node[font=\tiny, text=red]{\i}; }%% \end{circuitikz} \end{document}
- TikZ forest: how to add diagonal dots to a directory tree?by Grass on November 27, 2025 at 6:03 am
How do I draw a node of diagonal dots like this, for this base directory tree style by cfr? Ideally, I want this to work with ‘vertical dots’ --- the forest keys extensible edge and extend presented here by cfr. I tried looking at edge path to see if I what I could figure out, but not much luck thus far. As per Jasper’s request, here is an MWE (ripped from cfr’s post): \documentclass[border=10pt,multi,tikz]{standalone} \usepackage[edges]{forest} \definecolor{folderbg}{RGB}{124,166,198} \definecolor{folderborder}{RGB}{110,144,169} \newlength\Size \setlength\Size{4pt} \tikzset{% folder/.pic={% \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ; }, } \forestset{% declare autowrapped toks={pic me}{}, declare boolean register={pic root}, pic root=0, pic dir tree/.style={% for tree={% folder, font=\ttfamily, grow'=0, }, before typesetting nodes={% for tree={% edge label+/.option={pic me}, }, if pic root={ tikz+={ \pic at ([xshift=\Size].west) {folder}; }, align={l} }{}, }, }, pic me set/.code n args=2{% \forestset{% #1/.style={% inner xsep=2\Size, pic me={pic {#2}}, } } }, pic me set={directory}{folder}, pic me set={file}{file}, } \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] [templates ] [tests ] ] \end{forest} \end{document}
- TikZ word search diagramby yannis on November 26, 2025 at 11:50 pm
How can I draw such a "word-search" diagram in TikZ? I need to place the letters on a grid and then to add red horizontal, vertical, diagonal or antidiagonal highlighting boxes as in the picture.
- How to customize CircuiTikz ac - dc symbolsby Anisio Braga on November 26, 2025 at 8:12 pm
The ac & dc symbols in Circuitikz are a much welcomed addition. However, I could not find a proper way to customize it to a typical application in a multimeter dial with the ac or dc symbol positioned above the letter, besides changing the thickness of the lines. How can this be done with the new ac and dc symbols? I've used ac and dc symbols in a pictographic multimeter as illustrated. \documentclass[10pt]{article} \usepackage[usenames]{color} %used for font color \usepackage[siunitx,american, RPvoltages]{circuitikz} % DC and AC symbols \newcommand{\mathdirectcurrent}{\mathrel{\mathpalette\mathdirectcurrentinner\relax}} \newcommand{\mathdirectcurrentinner}[1]{% \settowidth{\dimen0}{$#1=$}% \vbox to .75ex {\offinterlineskip \hbox to \dimen0{\leaders\hrule height 0.65pt \hfill} \vskip.25ex \hbox to \dimen0{% \leaders\hrule height 0.35pt \hskip.25\dimen0\hfill \leaders\hrule height 0.35pt \hskip.25\dimen0\hfill \leaders\hrule height 0.35pt \hskip.25\dimen0 } \vfill }% } \newcommand{\textdirectcurrent}{\mathdirectcurrentinner{\textstyle}{}} %----------------------------------------- \newcommand{\DCACsup}[1]{$\widetilde{\stackrel{\mathdirectcurrentinner{}}{\rm #1}}$} \newcommand{\DCsup}[1]{$\stackrel{\mathdirectcurrentinner{}}{\rm #1}$} \begin{document} \begin{circuitikz} \node at (0,0)[ dc symbol, dc symbol segments=3]{V}; \node at (0, -1){\DCsup{V}}; \end{circuitikz} \end{document}
- TikZ forest: how to add vertical dots to the 'top' or bottom of a directory tree? (continuation)by Grass on November 26, 2025 at 5:37 am
A while back, cfr kindly answered my question here. But I have some issues. 1) I want to be able to insert vertical dots at any ‘level’ of the forest tree (Ref: cfr’s first comment) I want something like this: I tried \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,extensible edge [config ] [lib, extend [file.txt, file, extend ] [file, file] ] ] \end{forest} with cfr’s MWE but it gave 2) How to adapt the code so that it works with rounded corners (Ref: cfr’s second comment) When we use for tree={edge=rounded corners}, as in the following MWE, we have extraneous white space, which the removal of |- !u.child anchor seems to solve: \documentclass[border=10pt,multi,tikz]{standalone} % ateb: https://tex.stackexchange.com/a/754955/ \usepackage[edges]{forest} \definecolor{folderbg}{RGB}{124,166,198} \definecolor{folderborder}{RGB}{110,144,169} \newlength\Size \setlength\Size{4pt} \tikzset{% folder/.pic={% \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg, sharp corners] (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt); \filldraw [draw=folderborder, top color=folderbg!50, bottom color=folderbg, sharp corners] (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size); }, file/.pic={% \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10, sharp corners] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ; }, } \forestset{% declare autowrapped toks={pic me}{}, declare boolean register={pic root}, pic root=0, pic dir tree/.style={% for tree={% folder, font=\ttfamily, grow'=0, }, before typesetting nodes={% for tree={% edge label+/.option={pic me}, edge=rounded corners, }, if pic root={ tikz+={ \pic at ([xshift=\Size].west) {folder}; }, align={l} }{}, }, }, pic me set/.code n args=2{% \forestset{% #1/.style={% inner xsep=2\Size, pic me={pic {#2}}, } } }, pic me set={directory}{folder}, pic me set={file}{file}, declare toks={real siblings}{}, extensible edge/.style={% delay={% prepend={[\strut, delay={% do dynamics, temptoksa=, for following siblings={% if temptoksa={}{}{% temptoksa+={,}, }, temptoksa+/.option=name, }, real siblings/.register=temptoksa, folder, grow'=0, before computing xy={% l'=0pt, s'=-15pt, }, delay n=2{% split option={real siblings}{,}{append}, }, }, edge path'={% (!u.parent anchor) ++(\foresteregister{folder indent},0pt) -- ++(0pt,-5pt) edge [dotted] ([xshift=\foresteregister{folder indent}].parent anchor) }, ]}, }, }, extend/.style={% delay={% append={[\strut, folder, grow'=0, before computing xy={% l'=0pt, s'=-15pt, }, if n children=0{% before drawing tree={% delay={% y/.min={>O{y}}{parent,descendants}, }, }, }{}, edge path'={% (!uu.parent anchor |- !u.child anchor) ++(\foresteregister{folder indent},0pt) coordinate (a) -- ([yshift=15pt].parent anchor -| a) edge [dotted] (.parent anchor -| a) }, ]}, }, }, } \begin{document} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system, extensible edge, [config ] [lib [Access ] [Plugin ] [file.txt, file ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system [config ] [lib, extend [Access ] [Plugin ] [file.txt, file,extend ] ] ] \end{forest} \begin{forest} pic dir tree, pic root, for tree={% folder icons by default; override using file for file icons directory, }, [system,extensible edge [config ] [lib, extend [Access ] [Plugin ] [file.txt, file, extend ] ] ] \end{forest} \end{document} Edit I also want some lines to be of equal length, for aesthetic reasons:
- How to get a structure of this nodes tower with proper coordinates?by Explorer on November 25, 2025 at 5:54 pm
What I want to achieve is something as below(sorry for drawing in a hurry): The only requirements is vertical alignment(shown as the red dashed lines), the spacing of each nodes could be design, given that would not ruin the figure is okay. What I have tried is as below: \documentclass[tikz,border=5pt]{standalone} \newcommand\mynode[2][1]{% \node[draw,thick,minimum width=8cm,minimum height=2cm,font=\Huge\bfseries,scale=#1] at (#2) {AAAA}; } \begin{document} \begin{tikzpicture} % \mynode[1]{0,0} % \mynode[.45]{-2.25,-2} % \mynode[.45]{2.25,-2} % \mynode[.225]{-3.25,-3} % \mynode[.225]{1.25,-3} % \mynode[.225]{-1.25,-3} % \mynode[.225]{3.25,-3} %... \foreach \x[ evaluate=\x as \y using {int(2^(\x-1))} ] in {1,...,6}{ \foreach \t in {1,...,\y}{ \def\xx{\fpeval{-4 + (8/(\y+1))*\t*1.25}} \def\yy{\fpeval{(8/(\x+1))*1.25}} \mynode[\fpeval{1/\y}]{\xx,\yy} } } \end{tikzpicture} \end{document} It gives: I found that dilemma to determine the proper spacing, and exact coordinates calculation to guarentee vertical alignment at the same time. Is that any powerful tikz tools or something other (box, coffin?) to achieve this? Or I maybe just to make more effort to solve the better numerical relationship or working with the recursive structure?
- Is it possile to make smaller half lefts in Feynman-Tikz?by DominikSz on October 20, 2025 at 5:52 pm
I'm attempting to recreate the below diagrams using the feynman-tikz package. I've attempted the below code, \begin{subfigure}{0.4\textwidth} \centering \feynmandiagram[layered layout, horizontal = a to b]{ a -- [fermion] d -- [fermion, edge label =$e^-$] c -- [fermion] b, d -- [photon, half left, edge label =$\gamma$] c, }; \caption{An electron emits a photon which is then reabsorbed.} \end{subfigure} \begin{subfigure}{0.4\textwidth} \centering \feynmandiagram[horizontal = a to b]{ a -- [fermion] d -- [fermion, edge label=$e^-$] c -- [fermion] b, d -- [photon, quarter left, edge label=$\gamma$] e -- [fermion, half left=0.5cm, edge label=$e^-$] f -- [fermion, half left=0.1cm, edge label=$e^+$] e, f -- [photon, half left] c, }; \caption{Vacuum polarisation.} \label{fig:polarisation} \end{subfigure} however, my diagram (b) looks less than ideal, as shown below. Is there a way to make the latex diagram look more like the drawn one without having to resort to specifying vertices manually? Thanks.
- pgfplots: Using set layers in an overlay pictureby schtandard on July 5, 2025 at 1:58 pm
Using pgfplots, I want to draw a plot as an overlay picture, making use of layers inside that plot. However, when I say \begin{tikzpicture} [overlay] \pgfplotsset{set layers} \begin{axis} \end{axis} \end{tikzpicture} I get two ! Dimension too large. errors. pgfplots seems to attempt to set both unit lengths (\pgf@x and \pgf@y) to -32000.0pt. Why is that and how can I avoid it? For tinkering, here is a slightly more useful MWE. Interestingly, the result looks fine in this example. (In larger pictures, the errors do cause havoc, though.) \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} [remember picture] \draw [green] coordinate (test) circle [radius=5cm]; \end{tikzpicture} \begin{tikzpicture} [remember picture, overlay] \pgfplotsset{set layers} \begin{axis} [at=(test), anchor=center, ymajorgrids] \addplot+ {x^2}; \begin{pgfonlayer}{axis grid} \fill [red] (axis cs:3,20) circle [radius=2cm]; \end{pgfonlayer} \end{axis} \end{tikzpicture} \end{document}
- Tikz - ! Missing number, treated as zeroby Latexfan on July 5, 2025 at 5:48 am
I get error: ! Missing number, treated as zero. <to be read again> { l.34 } Here is the code: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[norsk]{babel} \usepackage{tikz} \usetikzlibrary{arrows.meta, angles, quotes, calc} \usepackage{amsmath} \begin{document} \begin{center} \begin{tikzpicture}[scale=0.65] \draw[very thin,color=gray] (-13,-1.5) grid (13,1.5); % Akser \draw[->, thick] (-13,0) -- (13.5,0) node[right] {$x$}; \draw[->, thick] (0,-1.5) -- (0,1.7) node[above] {$y$}; % x-aksen merker (flere π-enheter) \foreach \x/\lab in {-4/-4\pi, -3/-3\pi, -2/-2\pi, -1/-\pi, 1/\pi, 2/2\pi, 3/3\pi, 4/4\pi} \draw ({\x*3.14},0.1) -- ({\x*3.14},-0.1) node[below] {\small$\lab$}; % y-aksen merker \foreach \y in {-1,1} \draw (0.1,\y) -- (-0.1,\y) node[left] {\small$\y$}; % Selve grafen \foreach \k in {-2,-1,0,1,2} { \draw[domain=-3.14:0, thick, samples=50] plot(\x + {2*3.14*\k}, {-1*\x/3.14}); \draw[domain=0:3.14, thick, samples=50] plot(\x + {2*3.14*\k}, {\x/3.14}); } % Åpne punkter (grensepunkter) \foreach \k in {-2,-1,0,1,2} { \draw[fill=white] ({3.14*\k},0) circle (3pt); \draw[fill=white] ({3.14*(2*\k+1)},1) circle (3pt); \draw[fill=white] ({3.14*(2*\k+1)},-1) circle (3pt); } \end{tikzpicture} \end{center} \end{document} What should I change in the code? Thanks
- Given a normal vector, is it possible to re-orient tikz arrows and node letters so that they are level with an arbitrary plane?by Jasper on October 5, 2024 at 2:23 am
Note: I realize that this question is asking a lot, I just really want this functionality. Sorry for such a long and involved question. Also, a normal vector to the plane in my diagram is (1.5,-2,1). Given a normal vector, is it possible to re-orient tikz arrows and node letters so that they are level with an arbitrary plane? Similar to how the arrow is drawn in perspective in this example from page 84 of the asymptote manual: https://tex.stackexchange.com/a/267497/319072 is above my level, though it does seem to implement this feature, given angles. I want to do something similar, using a normal vector. https://tex.stackexchange.com/a/531156/319072 only seems to implement is for the xy, yz and xz planes. Here is a non-MWE (the reason for it being so long is to help you visualize the problem) \documentclass[tikz, border=0.2cm]{standalone} \usetikzlibrary{spy} \usepackage{tikz-3dplot} \newcommand{\planeFunction}[2]{ % Purpose: defines a plane. % #1 - x variable % #2 - y variable % Return: the output in z. -1.5*(#1)+2*(#2)+2 } \begin{document} \tdplotsetmaincoords{60}{45} \begin{tikzpicture}[tdplot_main_coords,spy using outlines={circle, magnification=4, size=2cm, connect spies}] % plane \foreach \Vt in {-2,-1.9,...,1}{ \draw[very thin,densely dotted] (\Vt,-2,{\planeFunction{\Vt}{-2}}) -- (\Vt,1,{\planeFunction{\Vt}{1}}); \draw[very thin,densely dotted] (-2,\Vt,{\planeFunction{-2}{\Vt}}) -- (1,\Vt,{\planeFunction{1}{\Vt}}); } % xy grid \foreach \Vt in {-2.8,-2.6,...,2.8}{ \draw[very thin,densely dotted] (\Vt,-3) -- (\Vt,3); \draw[very thin,densely dotted] (-3,\Vt) -- (3,\Vt); } % xy axes \draw[->] (-3,0) -- (3,0) node[pos=1,below right] {$x$}; \draw[->] (0,-3) -- (0,3) node[pos=1,above right] {$y$}; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% arrow on xy grid - how do I make it level with the plane? %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \spy on (2.8,0) in node at (6,-2); % shadow of domain on the xy plane \fill[opacity=0.3] (-2,-2) -- (-2,1) -- (1,1) -- (1,-2) -- cycle; \begin{scope} \clip (-4/3,-2) -- (1,-0.25) -- (1,1,{\planeFunction{1}{1}}) -- (-2,1,{\planeFunction{-2}{1}}) -- (-2,-2,{\planeFunction{-2}{-2}}) -- cycle; \fill[white] (-4/3,-2) -- (1,-0.25) -- (1,1,{\planeFunction{1}{1}}) -- (-2,1,{\planeFunction{-2}{1}}) -- (-2,-2,{\planeFunction{-2}{-2}}) -- cycle; % plane \foreach \Vt in {-2,-1.9,...,1}{ \draw[very thin,densely dotted] (\Vt,-2,{\planeFunction{\Vt}{-2}}) -- (\Vt,1,{\planeFunction{\Vt}{1}}); \draw[very thin,densely dotted] (-2,\Vt,{\planeFunction{-2}{\Vt}}) -- (1,\Vt,{\planeFunction{1}{\Vt}}); } \end{scope} % intersection line \draw (1,-0.25) -- (-4/3,-2); % shadow of plane \fill[opacity=0.3] (1,-2,{\planeFunction{1}{-2}}) -- (1,1,{\planeFunction{1}{-2}}) -- (1,1,{\planeFunction{1}{1}}) -- cycle; \fill[opacity=0.3] (1,-2,{\planeFunction{1}{-2}}) -- (-2,-2,{\planeFunction{1}{-2}}) -- (-2,-2,{\planeFunction{-2}{-2}}) -- cycle; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% arrow on plane - how do I make it level with the plane? %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \draw[->] (0,0,{\planeFunction{0}{0}}) -- (-1,-1,{\planeFunction{-1}{-1}}); \spy on (-1,-1,{\planeFunction{-1}{-1}}) in node at (-4,7); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% letter on plane - how do I make it level with the plane? %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \node at (-1.5,0.5,{\planeFunction{-1.5}{0.5}}) {$\overline{C}$}; \spy on (-1.5,0.5,{\planeFunction{-1.5}{0.5}}) in node at (-6,0); \end{tikzpicture} \end{document}
- Using latex tikz package alongside anki version 23.12.1by croakouttatune on February 25, 2024 at 4:44 am
Summary of the problem I've been attempting to get the latex tikz package working alongside my anki version (23.12.1) without success. I've also posted about this problem directly to the anki forum. I'm doing this (working with tikz) to include drawing that are illustrative to my flashcard notes in anki. I use a markdown convertion notetaking process, that is described and documented in github dot com slash lervag slash apy, but for most part this is exactly the same as adding the notes directly with the anki editor. This is the particular drawing that I've been trying to configure. [latex] \begin{tikzpicture} % Draw the circles \draw[thick] (0,0) circle (1); \draw[thick] (0,0) circle (2); \draw[thick] (0,0) circle (3); % Add lines to labels \draw[->, thick] (0,0.2) -- (4,0.2) node[right] {Identity}; \draw[->, thick] (0,1.5) -- (4,1.5) node[right] {Processes}; \draw[->, thick] (0,2.5) -- (4,2.5) node[right] {outcomes}; \end{tikzpicture} [\latex] I had thought that as soon as I added the tikz package to the premable that the problem would resolve itself. This is the updated preamble. \documentclass[12pt]{article} \special{papersize=3in,5in} \usepackage{tikz} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{amssymb,amsmath} \usepackage{tabularx} % added line for tables \usepackage[table]{xcolor} % added to color rows \pagestyle{empty} \setlength{\parindent}{0in} \begin{document} [X] I also have the "create scalable images with dvisvgm" checked off. HOWEVER, this doesn't seem to be the case and instead the text is rendered as the plaintext coding directly into the flashcard. Research into a solution I've looked up other posts on the topic, and couldn't find anything specifically geared towards tikz but instead found an article focused on getting the latex working within anki. Things That I've Tried I installed the Edit latex build process that is also described in the anki webseite documentation, and re-configured the build process to include pdflatex, which is in my path, and which I use for testing tex documents in vim with the command, autocmd BufWritePost *.tex execute "!pdflatex --shell-escape -output-directory=/tmp/ %" , and the configuration in the Edit latex build process is as follows: { "pngCommands": [ [ "latex", "-interaction=nonstopmode", "tmp.tex" ], [ "dvipng", "-D", "200", "-T", "tight", "tmp.dvi", "-o", "tmp.png" ] ], "svgCommands": [ [ "pdflatex", "-output-format=dvi", "-shell-escape", "-interaction=nonstopmode", "tmp.tex" ], [ "dvisvgm", "--no-fonts", "-Z", "2", "tmp.dvi", "-o", "tmp.svg" ] ] } I've noticed that when the command doesn't execute with success the error is rendered in place of the image, since this occurred a few times when I attempted the process of adding latex sections in the anki editor.
- How to plot this parametric curveby user248344 on January 18, 2022 at 7:08 am
I am trying to plot this parametric function: (cos(t)+(t)*sin(t), sin(t)+(t)*cos(t)) (0≤t≤π) which gives the curve below: This is my attempt, but for some reason it doesn't work. \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[thick] plot[variable=\t,domain=0:180,smooth,thick] ({cos(\t)-(\t)*sin(\t)},{sin(\t)-(\t)*cos(\t)}); \end{tikzpicture} \end{document} How should I fix these codes?
- Create triangle solving problemsby Zuriel on February 26, 2020 at 8:23 pm
I am hoping to create a triangle-solving problem generator, similar to the one here. My goal is to automatically generate different triangle solving problems for my students. Say given A=49°, b=5 and c=7, I am hoping that the program will generate the picture below. Similarly it would be great for the system to allow me to enter the triangle data by other axioms such as SSS, ASA. I have tagged tikz-pgf here but other drawing languages are welcome.
- Fun with Tikz Dogsby GermanShepherd on February 14, 2019 at 11:58 am
I am aware of the many fun uses of LaTeX such as the ever growing tikzlings package. Is anyone aware of any package to depict dogs? Edit 1 This may be quite selfish, any idea how to draw a simple German shepherd?. For those unfamiliar with dog breeds, it looks like this. Disclosure: Inspired by @marmot's icon 🙂
- Color fraction of table cellby O Ganter on November 12, 2018 at 9:38 pm
Is there some way to color only part of a table cell? For example, the top third, or bottom half of a cell? For example: \renewcommand{\arraystretch}{3.0} \begin{tabularx}{10cm}{|X|X|} \hline Row 1 & \cellcolor{blue!25} 1/3 colored \\ \hline Row 2 & uncolored \\ \hline \end{tabularx} \renewcommand{\arraystretch}{1.0} \begin{tabularx}{10cm}{|X|X|} \hline &\cellcolor{blue!25} \\ & \\ & \\ \hline & \\ & \\ & \\ \hline \end{tabularx} \renewcommand{\arraystretch}{1.0} \begin{tabularx}{10cm}{|X|X|} \hline Row 1 &\cellcolor{blue!25} 1/3 colored\\ & \\ & \\ \hline Row 2 & uncolored \\ & \\ & \\ \hline \end{tabularx} The first case shows how the text should appear, but clearly the cell is fully colored. In the second case, I split the two rows into six rows so that one third of the original cell can be individually colored. But when adding the text, it is no longer center in the middle of the true cells because it is put in the subcells. What is the best way to do this?
- pdflatex not working anymore after updating pdflatex.ini and initexmf --dump=pdflatexby user140574 on August 3, 2017 at 10:36 am
I tried to overcome the well known tex capacity exceed problem, when using large Surf-plot with many datapoints. I tried this by typing into the cmd (Windows 7, MikTex 2.9): initexmf --edit-config-file=pdflatex main_memory=5000000 extra_mem_bot=5000000 font_mem_size=5000000 pool_size=5000000 buf_size=5000000 **initexmf --dump=pdflatex** Now, pdflatex does not work anymore, a dvi is built, but no output. The log also says that the system maybe just failed. pdflatex is broke... Any Ideas? (I cannot think of a proper MWE.)
- How to prune nodes in a tree using graph syntaxby Charl Meyers on March 2, 2016 at 10:33 am
I want to indicate that nodes have been removed from a tree. Lets say the code looks like this: \documentclass{article} \usepackage{tikz} \usetikzlibrary{graphs} \usetikzlibrary{graphdrawing} \usegdlibrary{trees} \begin{document} \tikz[tree layout]\graph[nodes={draw, circle}] { a -- {b -- {e -- {k[label=below:1], l[label=below:4]}, f -- m[label=below:6]}, c -- g -- {y[label=below:0], z[label=below:2]}, d -- i[label=below:4]} }; \end{document} And I want to cut off b to f. How do I do it? I am using this syntax because this looks familiar to dot language and I am not very antiquated with latex. P.S. have a look at http://www.graphviz.org/doc/info/lang.html if you don't know that dot language is.
- Help drawing a very simple number line using TikZby JimmyJackson on December 3, 2013 at 11:16 pm
I want to draw a very simple number line, i found some code that got me started here. I have modified the code to get the following picture The problem is that I want the numbers below the line to show up as {-3,2,1,0,1,2,3} but I can't figure out how to modify the following code to do this. \usetikzlibrary{arrows} \begin{tikzpicture} \draw[latex-] (-6.5,0) -- (6.5,0) ; \draw[-latex] (-6.5,0) -- (6.5,0) ; \foreach \x in {-6,-4,-2,0,2,4,6} \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt); \foreach \x in {-6,-4,-2,0,2,4,6} \draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] {$\x$}; \draw[*-o] (0.92,0) -- (2.08,0); \draw[very thick ] (0.92,0) -- (1.92,0); \end{tikzpicture} It would nice if I could just divide \x by 2 in place of node[below] {$\x$}, but I don't know how to do this. Thanks!