TikZ
- Water molecule in tikz [duplicate]by Andy Fletcher on June 29, 2026 at 3:26 pm
How can I draw a water molecule using tikz like the ones in the image below with "H" in hydrogen atoms and "O" in oxygen atom?
- Straight lines in a matrixby Andy Fletcher on June 28, 2026 at 12:14 pm
I'm trying to draw straight lines in a matrix using nicematrix, and I achived the code: \documentclass{article} \usepackage{nicematrix,tikz} \begin{document} \begin{equation*} \begin{bNiceMatrix} \CodeBefore[create-cell-nodes] \begin{tikzpicture} %\draw[blue,-] (3-1) -- (4-2) ; %\draw[blue,-] (4-2) -- (3-4) ; \draw[blue,-] (3-1.north west) -- (4-2.south east) ; \draw[blue,-] (4-2.south east) -- (3-4.north east) ; \end{tikzpicture} \Body a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \end{bNiceMatrix} \end{equation*} \end{document} My problem is the straight lines are not centered in the entries of the matrix (see image below); I considered also \draw[blue,-] (3-1) -- (4-2) ; \draw[blue,-] (4-2) -- (3-4) ; instead of \draw[blue,-] (3-1.north west) -- (4-2.south east) ; \draw[blue,-] (4-2.south east) -- (3-4.north east) ; but in this case the two line are not linked. Any hint (desirably keeping the matrix created by nicematrix)? Thanks.
- How to draw a diagram in math-mode or in-line LaTeX?, for example, the following kind of diagram? What packages do I require?by Sagnik Roy on June 28, 2026 at 7:04 am
I need to draw the following and similar kind of diagrams with labels inside an LaTeX article.
- Spacing TikZ pictures with \hspace and \vspaceby LMPogoda on June 26, 2026 at 8:42 pm
I have several TikZ pictures. These are a set of rectangles with some nodes inside, creating a grid on a page. These are spaced by \hspace horizontally and \vspace vertically. It mostly works unless \hspace is just after the \vspace. When I want to push a TikZ picture toward right margin after \vspace, \hspace doesn't work. I think it is related to a switch from vertical to horizontal mode, but I haven't mastered it yet. I removed the nodes from TikZ code, but what matters (and does not work) is left intact. \documentclass[a4paper]{article} \usepackage{geometry} \geometry{a4paper,top=10mm,bottom=27mm,hmargin=10.0mm} \usepackage{tikz} \usepackage{graphicx} \pagestyle{empty} \setlength\parindent{0pt} \begin{document} \begin{tikzpicture} \draw[rounded corners=2pt] (0,0) rectangle (60.00mm,60.00mm); \end{tikzpicture}\hspace{5mm} \begin{tikzpicture} \draw[rounded corners=2pt] (0,0) rectangle (60.00mm,60.00mm); \end{tikzpicture}\hspace{5mm} \begin{tikzpicture} \draw[rounded corners=2pt] (0,0) rectangle (60.00mm,60.00mm); \end{tikzpicture}\vspace{5mm} \hspace{65mm}\begin{tikzpicture} \draw[rounded corners=2pt] (0,0) rectangle (60.00mm,60.00mm); \end{tikzpicture}\hspace{5mm} \begin{tikzpicture} \draw[rounded corners=2pt] (0,0) rectangle (60.00mm,60.00mm); \end{tikzpicture}\vspace{5mm} \end{document} Edit: I replaced code snippet with complete document for better clarity.
- tcolorbox: Using tikz pattern for drop shadowby Craig on June 26, 2026 at 6:21 pm
MWE: \documentclass{standalone} \usepackage{tcolorbox,tikz} \usetikzlibrary{patterns,patterns.meta} \begin{document} \begin{tcolorbox}[ sharp corners, rounded corners=downhill, ] Hello world \end{tcolorbox} \end{document} I have a tcolorbox. I would like the drop shadow to be made of the tikz pattern north east lines. I know tikz patterns can be used to fill parts of the tcolorbox itself (such as with title style={preaction={fill=white},pattern=crosshatch dots,pattern color=black}), but can this same trick also be used for drop shadows?
- Interaction between drawing something in the background and a page of floatsby Werner on June 26, 2026 at 3:59 am
In the following setup, I have a couple of images that forms part of a very large figure. The float ends up on a page of floats (on its own), because of the size. I plan on drawing some elements in the background, simulated by the background fill being the example images via \AddToHookNext{shipout/background}{<background drawing>}: \documentclass{article} \usepackage{lipsum,tikz} \begin{document} \lipsum[1-2] \begin{figure} \centering \tikz [remember picture] \node [inner sep = 10pt] (image-a) {\includegraphics[width = 0.5\linewidth]{example-image-a}}; \bigskip \tikz [remember picture] \node [inner sep = 10pt] (image-b) {\includegraphics[width = 0.5\linewidth]{example-image-b}}; \bigskip \tikz [remember picture] \node [inner sep = 10pt] (image-c) {\includegraphics[width = 0.5\linewidth]{example-image-c}}; \caption{A large figure} \AddToHookNext{shipout/background}{% \begin{tikzpicture}[remember picture, overlay] \filldraw [draw = red, fill = red!10!white, thick] (image-a.south west) rectangle (image-a.north east); \filldraw [draw = blue, fill = blue!10!white, thick] (image-b.south west) rectangle (image-b.north east); \filldraw [draw = green, fill = green!10!white, thick] (image-c.south west) rectangle (image-c.north east); \end{tikzpicture}} \end{figure} \lipsum[3-10] \end{document} Using this approach, however, puts the background drawing on the page where the original figure is processed, rather than where the actual figure is placed. How can I adjust the code so that the background content is placed correctly on the page where the float ends up? Ideally I'd like to keep the code as part of the figure as it semantically belongs with the figure, rather than placing it at some other bizarre place in the document just to make sure it fits there.
- How can I generate random numbers that are unique using pgftikz?by Matt on June 25, 2026 at 7:50 pm
I am trying to generate worksheets where each time \A is called for in the document, a random number is generated. I use \NewNumbers to make sure each \A within a section is identical. How can I make it so that each \A after the \NewNumbers command is different? \documentclass[addpoints, 12pt, answers]{exam} \usepackage[margin=1in]{geometry} \usepackage{amsmath, amssymb, lmodern, pgfmath, tikz, tcolorbox, multicol} \renewcommand{\familydefault}{\sfdefault} \pointformat{} \renewcommand{\TheSolution}[1]{ \pgfmathparse{#1 <= 1 ? "Neither" : (isprime(#1) ? "Prime" : "Composite")} \pgfmathresult } \pgfmathsetseed{1} \newcommand{\NewNumbers}{ \pgfmathsetmacro{\A}{random(0,100)} } \begin{document} \printanswers \begin{questions} \begin{multicols}{3} \NewNumbers \question[1] $\A$ \fillin[\TheSolution{\A}] \NewNumbers \question[1] $\A$ \fillin[\TheSolution{\A}] \NewNumbers \question[1] $\A$ \fillin[\TheSolution{\A}] \end{multicols} \end{questions} \end{document}
- tikz stops working when using a style in \tikzsetby Harry on June 25, 2026 at 12:02 pm
I have gotten a code (given below the question) which produces this: It is fine, but I want to modify the refracted ray by changing \draw[very thick, ray] (C) -- (b); to \draw[very thick, ray2] (C) -- (b); (to plot the red dots less in refracted ray). However, once I do this, my Texwoks throws out Runaway argument? ! Paragraph ended before \pgfkeys@addpath was complete. <to be read again> \par l.76 \draw[very thick, ray2] (C) -- (b); ? I checked my ray2/.style and it seems everything is fine. How can I solve this? The whole code is here \documentclass{beamer} % 4:3 \usetheme{Madrid} \usecolortheme{seahorse} \usepackage{amsmath} \usepackage{amssymb} \usepackage{physics} \usepackage{tikz} \usepackage{tikz-3dplot} \usetikzlibrary{calc, decorations.markings, arrows.meta, angles, quotes, decorations.pathreplacing, shapes.geometric, bending} \usetikzlibrary{patterns,decorations.pathmorphing, shapes.symbols, shadings, positioning} \usepackage{amsfonts} \usepackage[utf8]{inputenc} \usepackage{fontenc} \usepackage[safe]{tipa} \usepackage{xcolor} \usepackage{booktabs} % 用于绘制专业的表格线 \usepackage{setspace} %\setmainfont{Times New Roman} % 或者任意支持音标的字体 \usepackage{array} %% Rays \begin{document} \begin{frame}[fragile] \frametitle{Polarization in Reflection and Refraction} \begin{tikzpicture}[line cap=round, line join=round] % ====================== 所有定义都在这里 ====================== % TikZ Styles (integrated) \tikzset{ ray/.style = { postaction=decorate, decoration={ markings, mark=at position .52 with \arrow{stealth}, mark=between positions 0.1 and 1.2 step 0.5cm with { \draw[fill=red, draw=red] circle[radius=1pt]; \draw[red, {Latex[length=1.3mm, width=1.5mm]}-{Latex[length=1.3mm, width=1.5mm]}] (0,-7pt) -- (0,7pt); } } }, ray2/.style={ postaction=decorate, decoration={ markings, % 所有位置画箭头 draw arrow mark=between positions 0.1 and 1.4 step 0.5cm with { \draw[red, {Latex[length=1.3mm,width=1.5mm]}- {Latex[length=1.3mm,width=1.5mm]}] (0,-7pt)--(0,7pt); }, % 每隔一个位置画点 draw point mark=between positions 0.1 and 1.4 step 1.0cm with { \fill[red] (0,0) circle[radius=1pt]; } } }, polray/.style = { postaction=decorate, decoration={ markings, mark=at position .52 with \arrow{stealth}, mark=between positions 0.1 and 0.4 step 0.5cm with { \draw[fill=red, draw=red] circle[radius=1pt]; }, mark=between positions 0.6 and 0.9 step 0.5cm with { \draw[fill=red, draw=red] circle[radius=1pt]; } } } } % Right Angle Mark (local definition) \def\MarkRightAngle[size=#1](#2,#3,#4){ \draw[thick] ($(#3)!#1!(#2)$) -- ($($(#3)!#1!(#2)$)!#1!90:(#2)$) -- ($(#3)!#1!(#4)$) } % Coordinates \coordinate (A) at (4,5); \coordinate (B) at (4,0); \coordinate (a) at (1,4.6); \coordinate (C) at (4,3); \coordinate (a') at (7,4.6); \coordinate (b) at (5.5,0); % Second Material (interface) \node[rectangle, top color=black!30, bottom color=white, minimum width=7cm, minimum height=3cm] at (4,1.5) {}; % Incident ray \draw[dashed] (A) -- (B); \draw[very thick, ray] (a) -- (C); % Reflected ray (polarized) \draw[very thick, polray] (C) -- (a'); % Refracted ray \draw[very thick, ray] (C) -- (b); % Right angle mark \MarkRightAngle[size=6pt](b,C,a'); % Angle labels \pic[draw, thick, "\small$\theta_\text{b}$", angle radius=0.5cm, angle eccentricity=1.7] {angle = A--C--a}; \pic[draw, thick, "\small$\theta_\text{r}$", angle radius=0.7cm, angle eccentricity=1.5] {angle = a'--C--A}; \pic[draw, thick, "\small$\theta_\text{t}$", angle radius=0.7cm, angle eccentricity=1.6] {angle = B--C--b}; % Labels \node at (1,3.3) {$n_1$}; \node at (1,2.7) {$n_2$}; % Explanatory text \end{tikzpicture} \end{frame} \end{document}
- Coloring a region of a sphere in 3D using TikZby John on June 23, 2026 at 11:15 am
I have just started using the 3d library in TikZ (and I'm quite new to the tikz package itself). I am modelling a physics problem; I want to draw a sphere that represents my system. The particularity of that sphere is to have regions delimited by parallel circles around the North and South poles; I would like to color these regions in a different shade than the rest of the sphere. I have been looking everywhere and I can't find how to do this (if it is possible); using \path and \fill doesn't seem to work. Sorry if it's a stupid question, thanks for your help! Here is my code (I'm also showing the θ,φ parametrization in my sketch; in commentary, my failed attempts for coloring the North Pole): \documentclass{article} \usepackage{tikz} \usepackage{tikz-3dplot} \usepackage{pgfplots} \begin{document} \begin{tikzpicture}[scale=3,tdplot_main_coords] \def\rvec{1.2} \def\thetavec{55} \def\phivec{35} \def\thetaRC{10} \shadedraw[tdplot_screen_coords,ball color = white] (0,0) circle (\rvec); \coordinate (O) at (0,0,0); \tdplotsetcoord{C}{\rvec}{\thetavec}{\phivec} \tdplotsetcoord{UD}{\rvec}{\thetaRC}{90} \tdplotsetcoord{UG}{\rvec}{\thetaRC}{-90} \draw[thick,->] (0,0,0) -- (1.7,0,0) node[anchor=north east]{$x$}; \draw[thick,->] (0,0,0) -- (0,1.7,0) node[anchor=north west]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,1.7) node[anchor=south]{$z$}; \draw[-stealth,very thick,color=green!60!black] (O) -- (C) node[above right=-2] {P}; \draw[dashed, color=green!60!black] (O) -- (Cxy); \draw[dashed, color=green!60!black] (C) -- (Cxy); \tdplotdrawarc[color=green!40!black]{(O)}{0.4}{0}{\phivec}{anchor=north}{\(\varphi\)} \tdplotsetthetaplanecoords{\phivec} \tdplotdrawarc[color=green!40!black,tdplot_rotated_coords]{(0,0,0)}{0.7}{0}{\thetavec}{anchor=south west}{\(\theta\)} \draw[dashed] (\rvec,0,0) arc (0:360:\rvec); \draw[thick] (\rvec,0,0) arc (0:110:\rvec); \draw[thick] (\rvec,0,0) arc (0:-70:\rvec); %\tdplotdrawarc[fill=green!40!black]{(0,0,.995*\rvec)}{.0998}{0}{360}{anchor=south west}{\(\theta\)}; %\path[fill=red,fill opacity=0.5] (0,0,\rvec) -- plot[variable=\t,domain=0:360] (xyz spherical cs:radius=\rvec,longitude=\t,latitude=90-\thetaRC); \end{tikzpicture} \end{document}
- Fraction bar crashes into superscript exponent in manually-drawn TikZ fractionby Oregon Math Tutor on June 22, 2026 at 9:38 pm
I'm reproducing this educational graphic for my Algebra 1 students: I'm drawing fractions manually (separate nodes for numerator, bar, denominator) rather than \frac{}{} so I can control individual font sizes and colors. Two spacing problems I can't fix: 1. The fraction bar crashes into the 2 superscript on the denominator 5² 2. (where a ≠ 0) has no breathing room below the denominator aⁿ Both stem from the bar and note being placed at hardcoded absolute y-coordinates with no structural relationship to the surrounding nodes. MWE (problem area marked): % ── PROBLEM 1: bar hardcoded at y=1.88, unrelated to midfive.north ── \node[font=\bfseries\fontsize{38}{38}\selectfont] (midfive) at (11.70,1.03) {5}; \node[font=\bfseries\fontsize{22}{22}\selectfont] at ($(midfive.north east)+(0.08,0.10)$) {2}; \draw[line width=1.8mm] (11.18,1.88) -- (12.22,1.88); % bar too close to "2" % ── PROBLEM 2: note hardcoded at y=0.78, unrelated to aden.south ── \node[font=\bfseries\fontsize{41}{41}\selectfont] (aden) at (5.76,1.52) {a}; \node[font=\bfseries\fontsize{24}{24}\selectfont] at ($(aden.north east)+(0.10,0.12)$) {n}; \node[font=\bfseries\fontsize{15}{15}\selectfont] at (4.22,0.78) {(where a $\neq$ 0)}; Full MWE: \documentclass[tikz,border=0pt]{standalone} \usepackage{fix-cm} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage[scaled=0.98]{helvet} \renewcommand{\familydefault}{\sfdefault} \usepackage{xcolor} \usetikzlibrary{calc} \definecolor{bggray}{HTML}{ECECEC} \definecolor{purpleA}{HTML}{6B2FEA} \definecolor{purpleB}{HTML}{8B43F5} \definecolor{purpleText}{HTML}{7A34F0} \definecolor{greenText}{HTML}{43D400} \definecolor{redExample}{HTML}{FF2946} \definecolor{textMain}{HTML}{202020} \newcommand{\Avar}{\textcolor{purpleText}{\textbf{a}}} \newcommand{\Nvar}{\textcolor{greenText}{\textbf{n}}} \newcommand{\NegNvar}{\textcolor{greenText}{\textbf{-n}}} \begin{document} \begin{tikzpicture}[x=1cm,y=1cm] \path[use as bounding box] (0,0) rectangle (16,9); \fill[bggray] (0,0) rectangle (16,9); \shade[left color=purpleA,right color=purpleB] (0,6.82) rectangle (16,9); \node[text=white, font=\bfseries\fontsize{28}{30}\selectfont] at (8,8.18) {Negative Exponent Rule}; \node[anchor=north west, text=textMain, align=left, text width=15.0cm] at (0.56,6.47) {% {\bfseries\fontsize{12.6}{18}\selectfont Any nonzero number, \Avar, raised to a negative exponent, \NegNvar,\\[5pt] equals one over that number raised to the positive exponent, \Nvar.} }; \draw[black, line width=1.1mm, rounded corners=1.2mm] (1.02,0.35) rectangle (7.42,4.34); \node[text=purpleText, font=\bfseries\fontsize{53}{53}\selectfont] (abase) at (2.08,2.56) {a}; \node[text=greenText, font=\bfseries\fontsize{26}{26}\selectfont] at ($(abase.north east)+(0.18,0.16)$) {-n}; \node[text=textMain, font=\bfseries\fontsize{34}{34}\selectfont] at (4.18,2.62) {=}; \node[text=textMain, font=\bfseries\fontsize{36}{36}\selectfont] at (5.78,3.42) {1}; \draw[line width=2.0mm] (5.12,2.63) -- (6.44,2.63); \node[text=purpleText, font=\bfseries\fontsize{41}{41}\selectfont] (aden) at (5.76,1.52) {a}; \node[text=greenText, font=\bfseries\fontsize{24}{24}\selectfont] at ($(aden.north east)+(0.10,0.12)$) {n}; \node[text=textMain, font=\bfseries\fontsize{15}{15}\selectfont] at (4.22,0.78) {(where \Avar\ $\neq$ 0)}; % PROBLEM 2 \fill[redExample] (8.86,3.10) rectangle (14.78,4.20); \node[text=white, font=\bfseries\fontsize{21}{21}\selectfont] at (11.82,3.65) {Example}; \node[text=textMain, font=\bfseries\fontsize{44}{44}\selectfont] (fivebase) at (9.62,1.70) {5}; \node[text=textMain, font=\bfseries\fontsize{24}{24}\selectfont] at ($(fivebase.north east)+(0.08,0.12)$) {-2}; \node[text=textMain, font=\bfseries\fontsize{34}{34}\selectfont] at (10.58,1.85) {=}; \node[text=textMain, font=\bfseries\fontsize{34}{34}\selectfont] at (11.70,2.53) {1}; \draw[line width=1.8mm] (11.18,1.88) -- (12.22,1.88); % PROBLEM 1 \node[text=textMain, font=\bfseries\fontsize{38}{38}\selectfont] (midfive) at (11.70,1.03) {5}; \node[text=textMain, font=\bfseries\fontsize{22}{22}\selectfont] at ($(midfive.north east)+(0.08,0.10)$) {2}; \node[text=textMain, font=\bfseries\fontsize{34}{34}\selectfont] at (13.18,1.85) {=}; \node[text=textMain, font=\bfseries\fontsize{34}{34}\selectfont] at (14.35,2.53) {1}; \draw[line width=1.8mm] (13.86,1.88) -- (14.84,1.88); \node[text=textMain, font=\bfseries\fontsize{36}{36}\selectfont] at (14.35,1.00) {25}; \end{tikzpicture} \end{document} What is the canonical way to: Position a manually-drawn fraction bar so it reliably clears a denominator's superscript, using node anchors rather than hardcoded y-coordinates? Add vertical space above a text node relative to the node above it?
- How to offset two bezier paths with specific ratio elegantly?by Explorer on June 22, 2026 at 8:44 am
Description: I want to plot the following result: Now I have the following code with visual TikZ editor: \documentclass[tikz,border=2pt]{standalone} \begin{document} \begin{tikzpicture}[ line cap=round,line join=round, scale=3,line width=2pt, ] \clip circle[radius=1cm]; \draw[green] (-0.988,-0.155) .. controls (-0.689,0.093) and (-0.531,0.081) .. (-0.454,0.114) .. controls (-0.099,0.175) and (0.111,0.132) .. (0.402,0.132) .. controls (0.617,0.127) and (0.819,0.132) .. (0.98,0.252) ; \draw[teal] (-0.15,-0.349) .. controls (0.072,-0.109) and (0.231,-0.119) .. (0.274,-0.119) .. controls (0.607,-0.167) and (0.729,-0.431) .. (0.832,-0.53) ; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \draw[blue] (0.41,0.129) -- (0.343,-0.126); \draw[magenta] (-0.988,-0.174) .. controls (-0.732,0.048) and (-0.542,0.071) .. (-0.428,0.096) .. controls (-0.189,0.148) and (0.123,0.124) .. (0.385,0.11) .. controls (0.361,0.027) and (0.338,-0.056) .. (0.314,-0.139) .. controls (0.483,-0.182) and (0.563,-0.256) .. (0.61,-0.303) .. controls (0.666,-0.359) and (0.742,-0.454) .. (0.811,-0.54); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \draw[line width=4pt] circle [radius=1cm]; \end{tikzpicture} \end{document} However, the magenta line was not so perfect, in other word: \draw[magenta] (-0.988,-0.174) .. controls (-0.732,0.048) and (-0.542,0.071) .. (-0.428,0.096) .. controls (-0.189,0.148) and (0.123,0.124) .. (0.385,0.11) .. controls (0.361,0.027) and (0.338,-0.056) .. (0.314,-0.139) .. controls (0.483,-0.182) and (0.563,-0.256) .. (0.61,-0.303) .. controls (0.666,-0.359) and (0.742,-0.454) .. (0.811,-0.54); is no the best practice in my opinion(for example, green one and magenta one was partly overlepped). My question is, if I want the pos=0.7 of green one, and the pos=0.35 of teal one, how to offset(or yshift) the subpath in this case? See the below for pos details: References: https://tex.stackexchange.com/search?q=user%3A16595%20offset%20nfold How to thicken the subpath's segment with specific position? What is a better approach to plot the double path style as a subpath?
- Draw simple figures: l3draw vs PGF performancesby PHL on April 30, 2026 at 3:08 am
I have some lua code that generates coordinates of many triangles/quadrilaterals I then want to draw/fill. See this answer about Penrose tilings for a concrete example. The drawing is actually done in TikZ via the luadraw package, but I am wondering if I can make the code faster by replacing TikZ with l3draw. Rewriting my actual code to remove TikZ and luadraw dependences (and use l3draw or any other drawing tool) is not a complex task, but will ask me some time due to my limited programming skills. So I would prefer to know in advance if this is a good idea or not. Apart possibly performance, is there any other reasons to use l3draw over pgf for this kind of task? Edit: I am not using TikZ/pgf for the rest of the document. Suggesting to use another environment (as picture) is a valid answer.
- How to encapsulate this interface or make some recursion design in this Graph Theory figure generally?by Explorer on May 4, 2025 at 6:42 pm
Description: My Target is to draw something like this: Notes that the quadrilateral's shape is a little arbitrary as the figure shown, and in Graph Theory, they are equivalent, so slight distortion is permitted. Now, I manually achieve that as below: \documentclass[tikz,border=8pt]{standalone} \usetikzlibrary{shapes.geometric,calc} \pgfmathsetseed{4321} \tikzset{line cap=round,line join=round} \begin{document} \begin{tikzpicture} \node[name=O1,regular polygon, regular polygon sides=5, draw,minimum size=5cm,inner sep=5pt] {}; \foreach \i in {1,...,5}{\fill (O1.corner \i) circle (1pt);} \node[name=O2,regular polygon, regular polygon sides=5, draw,minimum size=1cm,inner sep=5pt,rotate=30] {}; \foreach \i[evaluate = \i as \j using {int(mod(\i,5)+1)}] in {1,...,5}{% \fill (O2.corner \i) circle (1pt); \pgfmathsetmacro\rndlena{(rnd*30+85)/100} \pgfmathsetmacro\rndlenb{(rnd*30+85)/100} \pgfmathsetmacro\rndanga{-(15+rnd*20)} \pgfmathsetmacro\rndangb{(15+rnd*20)} % \node at (rand,rand) {(\rndlen,\rndanga,\rndangb)}; \coordinate (O2-corner \i\j) at ($(O2.corner \i)!\rndlena!\rndanga:(O2.corner \j)$); \fill (O2-corner \i\j) circle (1pt); \coordinate (O2-corner \j\i) at ($(O2.corner \j)!\rndlenb!\rndangb:(O2.corner \i)$); \fill (O2-corner \j\i) circle (1pt); \path (O2-corner \j\i) edge (O2-corner \i\j) (O2-corner \j\i) edge (O2.corner \i) (O2-corner \j\i) edge (O2.corner \j) (O2-corner \i\j) edge (O2.corner \i) (O2-corner \i\j) edge (O2.corner \j) (O1.corner \j) edge (O2-corner \j\i) edge (O2-corner \i\j) ; } \begin{scope} \node[name=O3,regular polygon, regular polygon sides=5, draw,minimum size=.5cm,inner sep=0pt,rotate=30] at (-.75,1.2) {}; \foreach \i/\p[evaluate = \i as \j using {int(mod(\i,5)+1)}] in% {% 1/{O1.corner 2}, 2/{O2-corner 21}, 3/{O2.corner 1}, 4/{O2-corner 51}, 5/{O1.corner 1}% } {% \pgfmathsetmacro\rndlena{(rnd*20+40)/100} \pgfmathsetmacro\rndlenb{(rnd*20+40)/100} \pgfmathsetmacro\rndanga{-(50+rnd*30)} \pgfmathsetmacro\rndangb{(50+rnd*30)} % \node at (rand,rand) {(\rndlen,\rndanga,\rndangb)}; \fill (O3.corner \i) circle (1pt); \coordinate (O3-corner \i\j) at ($(O3.corner \i)!\rndlena!\rndanga:(O3.corner \j)$); \fill (O3-corner \i\j) circle (1pt); \coordinate (O3-corner \j\i) at ($(O3.corner \j)!\rndlenb!\rndangb:(O3.corner \i)$); \fill (O3-corner \j\i) circle (1pt); \path (O3-corner \j\i) edge (O3-corner \i\j) (O3-corner \j\i) edge (O3.corner \i) (O3-corner \j\i) edge (O3.corner \j) (O3-corner \i\j) edge (O3.corner \i) (O3-corner \i\j) edge (O3.corner \j) %% a bit dummy here (\p) edge (O3-corner \j\i) edge (O3-corner \i\j) ; } \end{scope} \end{tikzpicture} \end{document} which yields: Difficulity: I mainly confrant with these predicament: Inconsisit Coordinate System to locate O2-corner 21(TikZ banned me to use dot here) and O2.corner 2 I want to encapsulate the code in scope to be reused, however, it seemed to need five parameters in last edge operation (\p) edge (O3-corner \j\i) edge (O3-corner \i\j), and I found it difficult to design the command, or may be some recursion design. I manually assign some location/rotation arguments of O3 to adjust, which also make it not so elegant,and I have no idea to prevent from this(maybe the bottom edge to be parelell with five polygon's edge?). Question: How to better design and tune my first attempt on these kind of graph, with better syntax, consist coordinate system, and more widely(or general) interfaces to these kinds of figure(say that if the O1 is larger enough, I want the third layers' plot inside O3)? Some Coordinate Illustration as below in my MWE that maybe help: Best Wishes!
- How to automatically label through the dodecagon with TikZ elegantly?by Explorer on November 8, 2024 at 6:12 am
My Final Propose is to draw a picture as below, but each dots lie in the circle, or says dodecagon. I tried with the wheels created by Qrrbrbirlbel: With miminum size and the outer sep option, something went wrong with the float calculation causing errors. \documentclass[border=20pt]{standalone} \usepackage{tikz} \usetikzlibrary{math} \usetikzlibrary{positioning} %https://tex.stackexchange.com/questions/729843/how-to-position-the-node-with-tikz-positioning-relative-to-specific-angle \makeatletter \tikzset{angle/.code 2 args=\pgfmathsincos{#1}\tikz@lib@place@handle@{#2}{180+#1}{\pgfmathresultx}{\pgfmathresulty}{#1}{1}} \makeatother \begin{document} \begin{tikzpicture} \node[ draw,fill,circle, %mininum size=3pt, inner sep=0pt,outer sep=3pt, label=above:{\scriptsize$a_{1,0}$}] (A0) {}; \foreach \ang[ count = \n, evaluate = \n as \prev using \n-1, evaluate = \ang as \labelang using {mod(450-30*\n,360)}, %evaluate = \ang as \edgeang using {mod(450-30*\n,360)}, ]in {330,300,...,60,30}{% \node[ draw,fill,circle, inner sep=0pt,outer sep=3pt, label=\labelang:{\scriptsize$ a_{1,\n}$} ] (A\n) [angle={\ang}{of A\prev}] {} edge[-latex] node[swap] {\scriptsize$\alpha_{\n}$} (A\prev); } \draw[-latex] (A0) -- (A11); \end{tikzpicture} \end{document} Then I temporarily reset the outer sep=0pt. I want to label the edge of the dodecagon outside each edge of the circle, but I couldn't find an option like pos provided by \node when using edge to set the label position $\alpha_{i,\n}$. In the below code, the label's position is not satisfactory. The code: \documentclass[border=20pt]{standalone} \usepackage{tikz} \usetikzlibrary{math} \usetikzlibrary{positioning} %https://tex.stackexchange.com/questions/729843/how-to-position-the-node-with-tikz-positioning-relative-to-specific-angle \makeatletter \tikzset{angle/.code 2 args=\pgfmathsincos{#1}\tikz@lib@place@handle@{#2}{180+#1}{\pgfmathresultx}{\pgfmathresulty}{#1}{1}} \makeatother \begin{document} \begin{tikzpicture} \node[ draw,fill,circle, %mininum size=3pt, inner sep=0pt,outer sep=0pt, label=above:{\scriptsize$a_{1,0}$}] (A0) {}; \foreach \ang[ count = \n, evaluate = \n as \prev using \n-1, evaluate = \ang as \labelang using {mod(450-30*\n,360)}, %evaluate = \ang as \edgeang using {mod(450-30*\n,360)}, ]in {330,300,...,60,30}{% \node[ draw,fill,circle, %mininum size=3pt, inner sep=0pt,outer sep=0pt, label=\labelang:{\scriptsize$ a_{1,\n}$} ] (A\n) [angle={\ang}{of A\prev}] {} edge[-latex] node[swap] {\scriptsize$\alpha_{\n}$} (A\prev); } \draw[-latex] (A0) -- (A11); \end{tikzpicture} \end{document} Is there a better solution to plot the figure as above(like shape=regular polygon)? And could my code be changed with less clumsy code (more elegantly)?
- TikZ: make a nice pattern at a small area if using \usetikzlibrary{patterns}by cis on April 9, 2024 at 2:39 pm
How can I make a nice pattern if I use \usetikzlibrary{patterns} (if possible not \usetikzlibrary{patterns.meta})? E.g. pattern lines not so thick and no overlap and smaler line distances. I don't find the keys in the file tikzlibrarypatterns.code.tex If I set \pgfmathsetlengthmacro\cardwidth{0.61em} and then line width=0.025*\cardwidth this has no effect. \documentclass[]{article} \usepackage{tikz} \usetikzlibrary{patterns} \pgfmathsetlengthmacro\cardwidth{0.61em}% card width \pgfmathsetlengthmacro\cardheight{9*\cardwidth/6}% card height \begin{document} text \begin{tikzpicture}[ mypattern/.style={% fill=violet!22, postaction={ pattern=crosshatch, %pattern=north east lines, % alternativ pattern color=violet, draw=none, line width=0.025*\cardwidth, % <---- no effect.......... }, },% ] \node[minimum width=\cardwidth, minimum height=\cardheight, draw, rounded corners=0.075*\cardwidth, line width=0.025*\cardwidth,% <---- line width of node frame mypattern, ]{}; \end{tikzpicture} text \end{document}
- Drawing 3D diceby Ole Christian on March 5, 2024 at 10:49 am
I want to create 3D dice in LaTeX. I am familiar with the excellent package "customdice", but it unfortunately only produces 2D images. I am also inspired by the answer from hpekristiansen to this question. It creates beautiful dice, but I am uanble to change from colored circles to the familiar circle symbols for the numbers 1 to 6. One idea I had was to try to put the images from customdice on each of the surfaces, but I am unable to make it work. I believe the package customdice doesn't agree well to the packages required in the question linked above. Could anyone help me create "normal" dice faces on the surfaces on the answer linked above?
- Question about a TikZ templateby Hicham on October 26, 2022 at 11:07 pm
I want to create something like this image below, but I didn't know how to start because I'm a beginner in TikZ
- How to create a half filled circle in tasks?by Azarang on October 12, 2022 at 8:45 pm
I'm trying to make the last circle half filled like how \skill{Office}{4.5} work. Here's my try: \documentclass[12pt, a4paper]{resume} % Use the custom resume.cls style \usepackage[left=0.4 in,top=0.4in,right=0.4 in,bottom=0.4in]{geometry} % Document margins \usepackage{tasks} \usepackage{tikz} \begin{document} \begin{rSection}{Skills} \vspace{1em} \begin{tasks}[style=itemize, column-sep=-35mm, label-align=center, label-offset={2mm}, label-width={2mm}, item-indent={5mm}](3)% \task[] \textnormal{MATLAB} \tikz\draw[black,fill=black] (0,0) circle (.5ex); \tikz\draw[black,fill=black] (0,0) circle (.5ex); \tikz\draw[black,fill=black] (0,0) circle (.5ex); \tikz\draw[black,fill=black] (0,0) circle (.5ex); \tikz\draw[black,fill=black] (0,0) circle (.5ex); \end{tasks} \end{rSection} How can I do that here?
- node labels: inherit node colorby pschulz on May 31, 2022 at 7:02 am
Is it possible for node labels to "inherit" their parent's color? More specifically, I'm doing this: \node[red, label = {[red]above:label}] {node}; but I want to be able to do this: \node[red, label = above:label] {node}; Here is an MWE: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node[red, label = above:label] at (-2, 0) {node}; \node[red, label = {[red]above:label}] at (2, 0) {node}; \end{tikzpicture} \end{document} which produces
- How to include `tikzpicture` in forest node?by Zarko on May 9, 2021 at 4:08 am
How to include tizpicture, for example defined in ducks package, to a forest node? Edit: Simplified MWE with comparison result using duck in tikzpicture and in forest. \documentclass[border=3.141592]{standalone} \usepackage{forest} \usetikzlibrary{ducks} \begin{document} \tikz[baseline]{\duck[signpost=1]}\quad \begin{forest} [\tikz{\duck[signpost=1]}] \end{forest} \end{document} As you can see, the duck image in forest node is not complete, missed is result of option signpost=1. I guess, that image is included before its process of duck drawing is complete. So far I didn't find a way how to delay inclusion of image, or better, how to correct include such images in forest node.
- Hurricane symbolsby Sebastiano on June 23, 2020 at 3:06 pm
There were hyperuragans mentioned on an Italian television channel. Does any of you know if there is a specific package in LaTeX, or fonts that reproduce hurricane symbols with numbers? The image is taken from https://image.shutterstock.com/image-vector/set-hurricane-scale-icons-symbolic-260nw-712052398.jpg.
- Simulating paintbrush strokes in TikZby bfootdav on February 16, 2019 at 3:26 am
I am wondering if there exists a way to simulate paintbrush strokes in TikZ when filling in a shape. So given the following: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \tikz{ \draw[fill=red](0,0)rectangle(10,10); } \end{tikzpicture} \end{document} Instead of a solid red shape I was hoping to make it look like the red part was painted on with a paintbrush. I'm not exactly sure how what that would look like but I'm guessing maybe some randomly wavy lines that are a little darker and some maybe that are a little lighter? And I guess one would want for the paintbrush to have a thickness so that you'd be able to see the difference between one stroke and the one next to it. Looking at examples of actual paintbrush strokes online it looks like the light/dark parts vary a little on each line but that might be a complication not worth pursuing. Having all the strokes go down would be fine but being able to indicate a directions would be cool. And while I'm sure something like this is possible in various image editing programs, I need to do this in TeX/LaTeX as part of an automated file generating process. Edit: I do not believe this is a duplicate of the chalkboard solution as that one appears to use a bunch of small dots whereas a paintbrush involves long wavy lines of varying shades of the root color. The results would look very different. It could be that the chalkboard question provides an idea for an approach but using it as-is would not be a solution to my question. Update 1: I have done some experimentation with using TikZ decorations with wavy, random lines with rounded corners and it seems like this could be a way forward but I haven't made anything that looks close to convincing. Update 2: As per below, here is a link to a picture of close-up of brush strokes. This is pretty exaggerated but gets the point across. Here is an attempt at using wavy random lines: \documentclass{article} \usepackage{tikz} \usetikzlibrary{decorations.pathmorphing} \begin{document} \begin{tikzpicture} \tikz[line width=.1mm]{ \draw[fill=red](0,0)rectangle(10,10); \draw[line width = .5mm,decorate,decoration={random steps,segment length=12pt,amplitude=1pt},rounded corners=.1pt, color=red!50!brown] (1.5,0) -- (1.5,10); \draw[line width = .5mm,decorate,decoration={random steps,segment length=12pt,amplitude=1pt},rounded corners=.1pt, color=red!50!brown] (1.65,0) -- (1.65,10); \draw[line width = .5mm,decorate,decoration={random steps,segment length=12pt,amplitude=1pt},rounded corners=.1pt, color=red!50!brown] (1.8,0) -- (1.8,10); \draw[line width = .5mm,decorate,decoration={random steps,segment length=12pt,amplitude=1pt},rounded corners=.1pt, color=red!50!brown] (1.95,0) -- (1.95,10); } \end{tikzpicture} \end{document} As you can see it looks terrible. Update 3: Let me give a bit more detail about what I'm looking for. I am looking for something to fill large geometric shapes like squares, rectangles, and circles with sizes from half a page to almost a full page with one color. I have a program that generates music in many different styles (I'm a composer) but have decided to add artwork to it as well. So far I'm sticking with 20th century Modernist stuff as a lot of it seems simpler to do. I did a Mondrian one already (the squares and rectangles on thick crossing lines). And what inspired this question was the works of Kazimir Malevich, specifically his Black Square, Black Cross, Red Square and a few others of a similar style. My software randomly generates "paintings" that look similar but not exactly the same (for example, the black square varies in size but is still large, the red square uses different random dimensions for the quadrilateral, the black circle has different random dimensions and placed at random, etc). I had thought that since these are so simple that my users would appreciate having it be a bit more interesting to look at with the simulated brush strokes. Unfortunately I don't have any specific examples of paintings/painters in mind, just some vague notion that brush marks could be seen on paintings like those if you look closely enough(though I have no idea if you can see the brush strokes in Malevich's paintings). But then making it too subtle might get lost on the user when looking at it on their computer or phone so being a bit exaggerated might be better? It also occurs to me that maybe the bumps of the canvas underneath might help with the illusion?
- How to join two TikZ figures together?by JP Janet on August 8, 2017 at 5:26 pm
I have two TikZ figures that are identically sized images saved as separate tex files. The images have vertical symmetry. I would like to plot one image of the same size, with the left half from the first image and the right half from the second image to compare them. The files are long and automatically generated and hence I don't want to modify the source TikZ files. I don't want to compile the source files and join rendered images as they will be updated.
- Pie chart size from Bordaigorlby Laura K on April 27, 2017 at 7:10 pm
I have been using this great pie chart code: How to draw Bar & Pie Chart The code is from Bordaigorl. I was wondering if anyone can see how it is possible to have two pie charts in the same environment with different sizes. The part of the code that is responsible for this is "scale" when you call the function pie chart: \begin{tikzpicture} [ pie chart, slice type={g}{giallo}, slice type={A}{rosso}, slice type={B}{blu}, pie values/.style={font={\small}}, scale=2 ] \pie{t=1, A in power}{66/g,34/A} \pie[xshift=2.2cm]% {t=2, B in power}{33/g,33/B} \end{tikzpicture} My question is: does anyone see how to create two "types" of pies, one with scale=2 and another with scale=2.5, for example? For the purpose of understanding, I will post an MWE based on the whole code created by Bordaigorl here. What I would like is to have the left pie chart in one scale and the pie chart on the right in another scale. Please note that I am not the one who designed this code and credit must be given to Bordaigorl: \documentclass[border=10pt,multi,tikz]{standalone} \definecolor{rosso}{RGB}{220,57,18} \definecolor{giallo}{RGB}{255,153,0} \definecolor{blu}{RGB}{102,140,217} \definecolor{verde}{RGB}{16,150,24} \definecolor{viola}{RGB}{153,0,153} \makeatletter \tikzstyle{chart}=[ legend label/.style={font={\scriptsize},anchor=west,align=left}, legend box/.style={rectangle, draw, minimum size=5pt}, axis/.style={black,semithick,->}, axis label/.style={anchor=east,font={\tiny}}, ] \tikzstyle{bar chart}=[ chart, bar width/.code={ \pgfmathparse{##1/2} \global\let\bar@w\pgfmathresult }, bar/.style={very thick, draw=white}, bar label/.style={font={\bf\small},anchor=north}, bar value/.style={font={\footnotesize}}, bar width=.75, ] \tikzstyle{pie chart}=[ chart, slice/.style={line cap=round, line join=round, very thick,draw=white}, pie title/.style={font={\bf}}, slice type/.style 2 args={ ##1/.style={fill=##2}, values of ##1/.style={} } ] \pgfdeclarelayer{background} \pgfdeclarelayer{foreground} \pgfsetlayers{background,main,foreground} \newcommand{\pie}[3][]{ \begin{scope}[#1] \pgfmathsetmacro{\curA}{90} \pgfmathsetmacro{\r}{1} \def\c{(0,0)} \node[pie title] at (90:1.3) {#2}; \foreach \v/\s in{#3}{ \pgfmathsetmacro{\deltaA}{\v/100*360} \pgfmathsetmacro{\nextA}{\curA + \deltaA} \pgfmathsetmacro{\midA}{(\curA+\nextA)/2} \path[slice,\s] \c -- +(\curA:\r) arc (\curA:\nextA:\r) -- cycle; \pgfmathsetmacro{\d}{max((\deltaA * -(.5/50) + 1) , .5)} \begin{pgfonlayer}{foreground} \path \c -- node[pos=\d,pie values,values of \s]{$\v\%$} +(\midA:\r); \end{pgfonlayer} \global\let\curA\nextA } \end{scope} } \newcommand{\legend}[2][]{ \begin{scope}[#1] \path \foreach \n/\s in {#2} { ++(0,-10pt) node[\s,legend box] {} +(5pt,0) node[legend label] {\n} } ; \end{scope} } \begin{document} \begin{tikzpicture} [ pie chart, slice type={g}{giallo}, slice type={A}{rosso}, slice type={B}{blu}, pie values/.style={font={\small}}, scale=2 ] \pie{1}{66/g,34/A} \pie[xshift=2.2cm]% {2}{33.3/g,33.3/B,33.3/A} \end{tikzpicture} \end{document} I apologize if that is an obvious question. I've tried in 2 differents ways and they were all not succesful: I've tried to remove the scale from the preamble on tikz and added scale=2 when was calling pie function: \pie[xshift=2.2cm, scale=2]{2}{33.3/g,33.3/B,33.3/A} I've also tried to create two functions in the preamble of the document, one pie1 and another pie2. The code doesn't compile Thank you!
- Is it possible to make such an image with Tikz? How?by ThePunisher on March 17, 2016 at 10:34 am
I'm wondering what's the best way to render this image width the dashed line and with angles between normal lines and dashed lines. And also Is there a way to quickly rotate the tikz resulting image 90 degrees without rotating the letters? Thank you in advance
- Adding lighting effect to a rectangular glow box in TikZby Arianna Angeletti on February 6, 2012 at 12:35 pm
I would like to add to my first MWE in Can I have a glow around a box in TikZ? a lighting effect as shown in this example of the pgfmanual: By modifying the previous MWE: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \def\shadowradius{3pt} % \newcommand\drawshadowbis[1]{ \begin{pgfonlayer}{shadow} % \fill[inner color=blue,outer color=blue!10!black] ($(#1.south east)$) circle (\shadowradius); \fill[inner color=blue,outer color=blue!10!white] ($(#1.north west)$) circle (\shadowradius); %\fill[inner color=blue,outer color=blue!10!black] ($(#1.south west)$) circle (\shadowradius); %\fill[inner color=blue,outer color=blue!10!white] ($(#1.north east)$) circle (\shadowradius); % \fill[ top color=blue, bottom color=blue!10!black] ($(#1.south west)+((0,-\shadowradius)$) rectangle ($(#1.south east)$); \fill[left color=blue,right color=blue!10!black] ($(#1.south east)$) rectangle ($(#1.north east)+((\shadowradius,0)$); \fill[bottom color=blue,top color=blue!10!white] ($(#1.north west)$) rectangle ($(#1.north east)+((0,\shadowradius)$); \fill[right color=blue,left color=blue!10!white] ($(#1.south west)$) rectangle ($(#1.north west)+(-\shadowradius,0)$); \end{pgfonlayer} } % \pgfdeclarelayer{shadow} \pgfsetlayers{shadow,main} \begin{tikzpicture} \node [fill=blue,rectangle,rounded corners=0pt,draw=blue, ultra thick, text=white] (box) {Test!!!}; \drawshadowbis{box} \end{tikzpicture} \end{document} I get this: but I do not know how to define the colours of the missing angles. Any help will be really appreciated!
- Can I have a glow around a box in TikZ?by Johannes on January 30, 2012 at 4:15 pm
What I was wondering is, if I can have a glow effect for a box I am drawing with TikZ. Neither search here nor the (excellent) TikZ manual returned any results. There is a circular glow option, but I don't think that helps in my case, or does it!? Any input is appreciated :). Edit: I figured that these blurred shadows seem to be a fairly special PDF feature which is supported by few PDF viewers only (actually Acrobat Reader 9 for Linux was the only one that worked for me). (size of the blue box is the same)
- TikZ rectangular node with different rounded cornersby Arianna Angeletti on October 27, 2011 at 9:28 am
This is my minimal example: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node[rounded corners=3pt, draw, fill=red!20]{Hallo!}; \end{tikzpicture} \end{document} I'd like to define different values for rounded corners (i.e. 5pt for north-west and north-east and 2pt for south-east and south-west).
- What You See is What You Get (WYSIWYG) for PGF/TikZ?by Amelio Vazquez-Reina on July 27, 2011 at 3:30 pm
Are there any WYSIWYG editors for PGF/TikZ? Perhaps something similar to LyX but for PGF/TikZ? If there is no WYSIWYG editor for this tandem, is there one perhaps that allows the user to easily generate PGF/TikZ templates? Alternatively, how can I most easily generate PGF/TikZ code from a visual conception? Do people mostly code their PGF/TikZ graphics from scratch?
- Is there a way to draw 3D-style "buttons"?by Arianna Angeletti on December 22, 2010 at 12:09 pm
I was wondering if there is a latex package to get pseudo-3D style "buttons" as are often seen on the web, or if not is there an easy way to draw them? An example of what I mean: