TikZ
- How to add arrows from one point on one plot to another point on second plot in tikz and pgfplotsby Mr.Price on February 4, 2025 at 2:57 pm
I have the following code to plot 3 lines from which 2 are just a translation of main plot 2 points up and down. I want to highlight that fact by adding arrows pointing up and down (of length 2 point) from middle plot to two other plots. How can I do that nicely in tikz and pgfplots without manually calculating the position of points on plot and adding/subtracting 2 from y coordinate? I would like to add these arrows every 20% of plot length (so 5 arrows in total). \documentclass[tikz, margin=3mm]{standalone} \usepackage{tikz} \usetikzlibrary{shapes, backgrounds, arrows.meta, fit,decorations.pathreplacing} \usepackage[dvipsnames]{xcolor} \usepackage{pgfplots} \usepgfplotslibrary{fillbetween} \pgfplotsset{compat=1.18} \usepackage{polski} \begin{document} \begin{tikzpicture}[ % show background grid, background grid/.style={thin, dotted, draw=gray,step=.5cm}, >=Stealth, remember picture, ] \begin{axis}[ xmin=-3.5, xmax=3.99, ymin=-4.5, ymax=4.99, xtick distance=1, ytick distance=1, xticklabels=\empty, yticklabels=\empty, extra y ticks={1}, % Dodatkowy tick na osi Y (dla b=1) extra y tick labels={$1$}, % Oznaczenie wartości b extra x ticks={1}, % Dodatkowy tick na osi Y (dla b=1) extra x tick labels={$1$}, % Oznaczenie axis lines=middle, % Osie przechodzą przez środek axis line style={-Stealth}, % Strzałki na osiach axis on top, % Osie na wierzchu xlabel={$X$}, % Oznaczenie osi X ylabel={$Y$}, % Oznaczenie osi Y xlabel style={at={(ticklabel* cs:1)}, anchor=north east}, % Pozycja etykiety X ylabel style={at={(ticklabel* cs:1)}, anchor=north west}, % Pozycja etykiety Y grid=both, % Dodaj siatkę grid style={dotted, gray!50}, % Styl siatki: kropkowana, szara set layers, % Włącz warstwy clip mode=individual, legend style={font=\tiny, scale=0.8, legend cell align=left}, legend pos=south west% Zmniejsza legendę ] \begin{pgfonlayer}{axis foreground} \addplot [domain=-3:3, samples=100, thick, color=Red] {x} node[pos=0.9, above] {\textbf{$\textcolor{Red}{f}$}}; \addplot [domain=-3:3, samples=100, thick, color=Orchid] {x+2} node[pos=0.9, above] {\textbf{$\textcolor{Orchid}{g}$}}; \addplot [domain=-3:3, samples=100, thick, color=Cerulean] {x-2} node[pos=0.9, above] {\textbf{$\textcolor{Cerulean}{h}$}}; \end{pgfonlayer} \end{axis} \end{tikzpicture} \end{document}
- Using Deployment Diagrams in Latex (using tikz or tikz-uml)by Stephan1403 on February 4, 2025 at 1:54 pm
For my bachelors thesis I wanted to include a Deployment Diagram. For my other diagrams I found that using tikz-uml was the best. Unfortunately there seems to be no option to draw the 3d Boxes used in deployment diagrams with tikz-uml. What is the best way to include a deployment diagrams in my latex? P.s. this is my reference for tikz-uml: https://perso.ensta-paris.fr/~kielbasi/tikzuml/var/files/doc/tikzumlmanual.pdf
- TikZ Layers on custom codeby Emanuele Nardi on February 4, 2025 at 12:57 am
I'm working on adapting the code from How to Optimize a TikZ Animation of Quicksort? to use TikZ with layers. I want to add a layer that draws a rectangle with a very thick line. Additionally, I would like to include a line between the 7th and 8th elements, exactly in the middle of the vector. Furthermore, the labels should be positioned between the colored cells. More details are provided in the code. Desired output This is my current output: This is the output I would like to achieve: Code \documentclass[tikz, border=.2cm]{standalone} \usetikzlibrary{chains} % slide 11/52 \newcommand*\tikzqsset{\pgfqkeys{/tikz/qs}} \tikzqsset{ % default cell style vector/.style = {draw, shape=rectangle, minimum size = +0.7cm, outer sep = +0pt}, label/.style = {node distance = 0pt,font = \ttfamily\scriptsize}, % /tikz/label exists already % cells styles undiscovered/.style = {fill = white}, left/.style = {fill = red!30}, between/.style = {fill = yellow!30}, right/.style = {fill = blue!30}, % parsing style parse/.style args={#1#2}{qs/sc-#1/.try, node contents={#2}}, % defining styles sc-l/.style={in front of path, qs/undiscovered}, sc-L/.style={in front of path, qs/left}, sc-b/.style={in front of path, qs/between}, sc-r/.style={in front of path, qs/undiscovered}, sc-R/.style={in front of path, qs/right}, } \NewDocumentCommand{\DividiEtImpera}{ m }{ \tikz\path[node distance=+0pt, start chain=going right] { foreach[count=\i] \v in {#1}{ node[on chain, qs/vector, qs/parse/.expand once=\v] } } []; \tikz\draw[very thick] (chain-1.north west) rectangle (chain-16.south east); } \begin{document} \DividiEtImpera{l0, L1, L2, L3, L4, l5, b6, b7, b8, b9, b10, r11, r12, R13, R14, R15} % maxL label below and between 1 and 4 % maxRR label below and between 6 and 7 % maxLL label below and between 8 and 10 % maxR label below and between 13 and 15 \end{document}
- Draw Intervals using LaTeXby Averroes2 on February 3, 2025 at 7:33 pm
Does anyone has an idea how to draw this in LaTeX using TikZ: ChatGPT gave me this, but I cannot handle the arrows in order to correct it: \documentclass{article} \usepackage{tikz} \usepackage{amsmath} \usetikzlibrary{decorations.pathreplacing, positioning} \begin{document} \begin{center} \begin{tikzpicture} \draw[thick] (-6,0) -- (6,0); % Brackets \draw[decorate,decoration={brace,amplitude=6pt}] (-5.5,0.2) -- (-2.5,0.2) node[midway, above=4pt] {$k_L$}; \draw[decorate,decoration={brace,amplitude=6pt}] (-2.5,0.2) -- (-1,0.2) node[midway, above=4pt] {$i$}; \draw[decorate,decoration={brace,amplitude=6pt}] (-1,0.2) -- (1,0.2) node[midway, above=4pt] {$k_R$}; \draw[decorate,decoration={brace,amplitude=6pt}] (1,-0.4) -- (3,-0.4) node[midway, below=4pt] {$k_L'$}; \draw[decorate,decoration={brace,amplitude=6pt}] (3,-0.4) -- (5.5,-0.4) node[midway, below=4pt] {$k_R'$}; % Labels \node[above] at (-2.5,0) {$j$}; \node[above] at (3,0) {$j'$}; \node[below] at (-1,0) {$i$}; \node[below] at (1,0) {$i'$}; % Congruence Arrows \draw[dotted,->] (-2.5,0.3) to[out=60,in=120] (3,0.3) node[midway, above] {\textit{Cong}}; \draw[dotted,->] (-1,-0.5) to[out=-60,in=-120] (1,-0.5) node[midway, below] {\textit{Cong}}; \draw[dotted,->] (1,-0.6) to[out=-60,in=-120] (3,-0.6) node[midway, below] {\textit{Cong}}; \end{tikzpicture} \end{center} \end{document}
- How to join two differently-coloured lines nicely [duplicate]by jonnybolton16 on February 3, 2025 at 3:38 pm
I'm drawing a simple box with tikz, whose vertial sides are red and horizontal sides are blue. \begin{tikzpicture}[line width=2pt] % \draw[help lines,step=0.5] (-3,-3) grid (3,3); \draw[red] (-3,-3) -- (-3,3) (3,-3) -- (3,3); \draw[blue] (-3,-3) -- (3,-3) (-3,3) -- (3,3); \node at (0,0) {\huge\(\Omega\)}; \end{tikzpicture} But I don't like how the corners are notched: I know I could use line cap=rect, but this causes the corners to be entirely blue, since these are drawn second: Similarly, I know I could do something like (-3,-3) -- (-3,3) -- (3,3) -- (3,-3) -- cycle; to join the corners, but this would lose the two-colour design. Is there a simple way that I can get a corner that is half red/half blue along a 45 degree line?
- tikz calendar in matrix produces "Undefined control sequence"by karu on February 3, 2025 at 3:08 pm
Code below fails with "Undefined control sequence" \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calendar,matrix} \begin{document} \begin{tikzpicture} \newcommand{\calmonth}[3]{\calendar[dates = #1-#2-1 to #1-#3-last, week list];} \matrix (tester) [matrix of nodes] { \calmonth{2025}{1}{1} & 3 \\ 2 & 4 \\ }; \end{tikzpicture} \end{document} It produces this error message: ! Undefined control sequence. \iterate ...til@tempcntb }\tikz@before@day \scope \tikz@atbegin@day \tikz@li... l.8 \calmonth{2025}{1}{1} & 3 \\ ? If \newcommand is put before \begin{document}, the error message stays the same. However this works fine \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calendar,matrix} \begin{document} \begin{tikzpicture} \newcommand{\punct}[3]{\fill[color = #1] (#2 mm, #2 mm) circle[radius = #3 mm];} \matrix (tester) [matrix of nodes] { \punct{red}{0}{0.5} & 3 \\ 2 & 4 \\ }; \end{tikzpicture} \end{document} and this as well \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calendar,matrix} \begin{document} \begin{tikzpicture} \newcommand{\calmonth}[3]{\calendar[dates = #1-#2-1 to #1-#3-last, week list];} \calmonth{2025}{1}{1} \end{tikzpicture} \end{document} There must be some deeper magic that I don't get.
- I'm having trouble drawing the hands. I just need simple hands pushing and pulling the box. Can anyone help me with this?by Ismael Joaquim on February 3, 2025 at 12:35 pm
Just like the figure below: The following is my MWE. \documentclass{standalone} \usepackage{tikz} \usepackage{xcolor} \usepackage{amsmath,esvect} \usepackage{amssymb} \begin{document} \begin{tikzpicture} % Block being pushed \draw[fill, color=orange!80, draw=red] (0,0) rectangle (1,1) node[below, yshift=-1.2cm, xshift=-1cm, color=red] {Push}; % Force applied to the block (Push) \draw[-latex, line width=1mm, color=blue] (1,0.5) -- (2,0.5) node[above] {$\vv{F}$(Force)}; % Hand pushing the block \draw[-, rounded corners] (-1,-0.1) -- (0,0) -- (0, 0.6) -- (-0.1,0.15) (0,0.5) -- (0,0.95) -- (-0.25,0.25) -- (-1, 0.30); % Block being pulled \draw[fill, color=orange!80, draw=red] (2,0) rectangle (3,-1) node[right, below, yshift=0.3cm, xshift=0.7cm, color=red] {Pull}; % Force applied to the block (Pull) \draw[-latex, color=blue, line width=1mm] (3,-0.25) -- (4,-0.25) node[above] {$\vv{F}$}; % Gray line below the pulled block \draw[-, color=gray, line width=0.5mm] (3,-0.5) -- (4.25,-0.5); \end{tikzpicture} \end{document}
- Setting node font size from withinby Cactus on February 3, 2025 at 12:18 pm
In the following example, I would like to set the font size of a node from "inside" the node's contents, i.e. without changing the node's font attribute: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} %% From https://tex.stackexchange.com/q/359189/2113 \def\gobblechar{\let\xchar= } \def\assignthencheck{\afterassignment\xloop\gobblechar} \def\xloop{% \ifx\relax\xchar \let\next=\relax \else \phantom{8}\makebox[0pt][r]{\xchar} \let\next=\assignthencheck \fi \next} \def\cellbits#1#2{\assignthencheck#1\relax \\ \assignthencheck#2\relax} \begin{scope}[scale=0.5,every node/.style={font=\large,align=center}] \draw[thin, densely dotted] (0,0) grid (7,1); \begin{scope}[shift={(0.5,0.5)}] \draw (0,0) node{1}; \draw (2,0) node{\cellbits{123}{456}}; \draw (4,0) node[font=\tiny]{\cellbits{123}{456}}; \draw (6,0) node{\tiny\cellbits{123}{456}}; \end{scope} \end{scope} \end{tikzpicture} \end{document} The nodes at (0,0) and (2,0) are just for reference. The node at (4,0) is exactly the output I would like to get. The node at (6,0) illustrates my problem. The \tiny size seems to be applied only to the first line (until the \\), and the line spacing and the second line all have size \large, i.e. the one based on the node's default font attribute: What can I put inside the (6,0) node's contents to get the same output as the (4,0) node? P.s.: If it can't be done "compositionally" i.e. if I have to change the definition of cellbits / xloop to "push in" the \tiny-ness, that is not optimal, but still fine.
- I'm having trouble with this picture. How can I draw this rotate box?by Ismael Joaquim on February 2, 2025 at 7:55 am
\documentclass{article} \usepackage{tikz} \usepackage{tkz-euclide} \begin{document} \begin{tikzpicture} \coordinate (A) at (0,3); \coordinate (C) at (4,0); \coordinate (B) at (0,0); %TRIANGLE \draw[thick] (A) -- (B) -- (C) -- cycle; \draw[rotate=0, rounded corners] (2,-0.25) rectangle (2.6,0.25); \draw[rotate=0, rounded corners] (-0.3,2) rectangle (0.3,2.5); \draw[rotate=0, rounded corners] (1,2) rectangle (1.6,2.5); %VECTORS \draw[-latex, line width = 0.5mm] (0,2.25) -- (0,1.25); \draw[-latex, line width = 0.5mm] (2.3,0) -- (2.3,-1); %NODES \node[above] at (A) {$A$}; \node[left] at (B) {$B$}; \node[right] at (C) {$C$}; %ANGLE \tkzMarkAngle[size=0.6cm, dashed](A,C,B) \tkzLabelAngle(A,C,B){$\theta$} \end{tikzpicture} \end{document}
- How to change individual wire styles in quantikz?by AG47 on February 2, 2025 at 1:03 am
I am using the quantikz package to draw quantum circuits and I would like to be able to change the style (e.g. color, thickness...) of individual wires. The official documentation only explains how to change the wire style globally or the gate styles individually. I manage to obtain a partial solution by hacking the packge a bit: \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{quantikz2} \renewcommand{\fullwire}[4]{%direction with repetition. direction. type. decoration \edef\wiretype{#3} \ifstrequal{#3}{a}{%automatic determination \ifcsundef{wire@type@\the\pgfmatrixcurrentrow}{%type not defined globally. assume quantum. \edef\wiretype{q} }{% \edef\wiretype{\csname wire@type@\the\pgfmatrixcurrentrow\endcsname} \ifdefstring{\wiretype}{u}{% \edef\wiretype{q} }{} } \ifcsdef{wire@type@override@\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn}{% \edef\wiretype{\csname wire@type@override@\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn\endcsname} }{} }{} \ifdefstring{\wiretype}{q}{%quantum wire \arrow[#1,arrows,#4] {} }{% \ifdefstring{\wiretype}{c}{%classical wire \arrow[arrows,start anchor=#2startone,end anchor=#2endone] {#1}\arrow[arrows,start anchor=#2starttwo,end anchor=#2endtwo,#4] {#1} }{% \ifdefstring{\wiretype}{b}{%wire bundle \arrow[arrows,start anchor=#2startone,end anchor=#2endone,#4] {#1}\arrow[arrows,start anchor=#2starttwo,end anchor=#2endtwo,#4] {#1}\arrow[#1,arrows,#4] {} }{% \ifdefstring{\wiretype}{custom}{%cu \arrow[arrows,start anchor=#2startone,end anchor=#2endone,#4,draw=orange, dotted] {#1}\arrow[arrows,start anchor=#2starttwo,end anchor=#2endtwo,#4,draw=orange,dashed] {#1}\arrow[#1,arrows,#4,draw=orange] {} }{% \ifdefstring{\wiretype}{n}{%no wire }{\ifdefstring{\wiretype}{u}{%unset }{\arrow[arrows,start anchor=#2startone,end anchor=#2endone,draw=#3,#4] {#1}\arrow[arrows,start anchor=#2starttwo,end anchor=#2endtwo,draw=#3,#4] {#1}\arrow[#1,arrows,draw=#3,#4] {} }}}}}} } \begin{document} \begin{quantikz}[color=blue] & \gate{H} \wire{red, line width=2mm} & \wire{custom}\\ & & \end{quantikz} \end{document} Basically, I naively redefine the \fullwire command to check for a custom style custom that tries to play with the linestyle and change the color to orange. I also overrode the default behavior when the wiretype is not recognized to use the wiretype as style options instead. The \wire command calls \fullwire itself after tweaking its arguments. This feels sinful, all the more so that I think I should be able to pass these parameters as fourth argument of \fullwire (mapped to the third argument to \wire if I read the code correctly). It does not fully suit my need either, as it seems it cannot override the global color parameter (or another wire of that color is drawn on top of it). Only the first two \arrows seem to use the given parameter. I did not try using anything along: \tikzset{ arrow/.style={draw=red,line width=2mm} } because my current understanding is that it would at best modify all the wires at once.
- How do I create a bullet-shaped node using TikZ?by kuzzooroo on February 1, 2025 at 9:39 pm
In deep learning diagrams, I often see bullet-shaped nodes used to identify parts of the computational graph, like so: (image source) This shape is not in the shapes library in any natural way. Is there any easy to draw modules in this shape? (as opposed to creating something completely custom every time you want to do it)
- tikz /.style with arguments in custom environmentby Marco on February 1, 2025 at 4:17 pm
I want to define a custom style in a tikzpicture where the style has arguments. So I started with this first example, which is working: \documentclass[border=1mm]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[ width/.style={minimum width=#1,text width=#1-10pt, inner sep=5pt, outer sep=0pt} ] \node[draw,width=5cm] at (0,0) {Hello\\This is a very long line with a lot of text}; \end{tikzpicture} \end{document} I need this tikz settings in many places in my document, so my idea is to create a custom environment. But this is not working, because #1 is now the argument of my environment and not of the width./style any more. Here is the code which is NOT working: \documentclass[border=1mm]{standalone} \usepackage{tikz} \newenvironment{mypic}{\begin{tikzpicture}[ % Using #1 in the next line is the problem width/.style={minimum width=#1,text width=#1-10pt, inner sep=5pt, outer sep=0pt} ]}{\end{tikzpicture}} \begin{document} \begin{mypic} \node[draw,width=5cm] at (0,0) {Hello\\This is a very long line with a lot of text}; \end{mypic} \end{document} How to solve this? I give you some background information: I need to create many pictures in my document, so I want to avoid copy&paste all the styles for each tikzpicture. In the example above it is only one line, the real implementation has much more definitions. I know I can use tikzset to define global styles, but the environment "mypic" is only one type of images, my real implementation has many different types of images, for example "myumlpicture", "mystatechartpic", "mysomethingelsepic". In different types of images the definition of "width" is different, with a global "tikzset" I would get naming conflicts. I will also ask other people to create images, so it would be very convenient for them when I can provide custom environments. Also the name "width" is intuitive, I don't want to use different names for the width, for example "umlwidth", "statechartwidth". I don't know if it is important to know, but all the image files with \documentclass{standalone} will be used in a presentation \documentclass{beamer} with \usepackage{standalone}, each image will be included with \input{imagename}.
- Drawing dashed curves with tikzby Ismael Joaquim on February 1, 2025 at 11:22 am
I'm trying to draw these pictures with tikz, but I'm having some trouble with these two curves. \documentclass{article} \usepackage{tikz} \usepackage{amsmath} \usetikzlibrary{angles, quotes} \begin{document} \begin{tikzpicture}[scale=2,>=latex] % Definição de coordenadas \coordinate (O) at (0,0); \coordinate (A) at (1,0); \coordinate (B) at (1.5,0.8); \coordinate (C) at (1.2,1.3); % Vetores principais \draw[->,thick] (O) -- (A) node[midway,below] {$\vec{r}$}; \draw[->,thick] (O) -- (B) node[midway,above right] {$\vec{r} + d\vec{r}$}; \draw[->,thick] (A) -- (B) node[midway,above] {$d\vec{r}$}; % Arco tracejado \draw[dashed] (A) arc[start angle=0, end angle=30, radius=1]; % Ângulo theta \draw pic["$\theta$", draw=black, <->, angle eccentricity=1.2, angle radius=0.3] {angle=A--O--B}; % Força F(r) \draw[->, ultra thick, gray] (A) -- (C) node[midway,left] {$\vec{F}(r)$}; % Massa \fill (A) circle (2pt) node[below left] {$m$}; \end{tikzpicture} \end{document}
- Adjusting vertical spacing and segment lengths in a tikz forest diagramby sidat on February 1, 2025 at 7:08 am
I am trying to use the tikz forest package to recreate the manually typeset diagram shown here: Here is my code thus far: \documentclass{standalone} \usepackage[edges]{forest} \forestset{ fairly nice empty nodes/.style={ delay={where content={} {shape=coordinate, for siblings={anchor=north}}{}}, for tree={s sep=4mm} }} \begin{document} \begin{forest} fairly nice empty nodes, for tree={ % style of tree (edges, distances, direction) grow = south, forked edge, % for forked edge s sep = 3mm, % "sibling" distance l sep = 4mm, % "level" distance fork sep = 3mm, % distance from parent to branching point align = center } [root [node 1 line 1\\node 1 line 2, calign=last [node 2 line 1\\node 2 line 2 [node 3]] [node 4 line 1\\node 4 line 2\\node 4 line 3\\node 4 line 4, calign=last [node 5] [node 6] [ [,l=10mm [node 7] [node 8] [node 9] [node 10] [node 11] [node 12] ] ] ] ] ] \end{forest} \end{document} It generates this tikz diagram: While it is close to the manually typeset version, there are some differences. Specifically, there are three areas of concern as noted on the tikz diagram. I would like to have less vertical space at the points shown in blue, and I would like to lengthen the vertical line segments indicated by the green arrows so that they match the length of the corresponding segments above terminal nodes 7-12. Lastly, I would like to elongate the vertical segment highlighted in red. I used ",l=10mm" to elongate the segment above the terminal nodes, but that method doesn't appear to work for the red segment.
- pgfplots fpu output to valid marker size?by Xaser on January 31, 2025 at 9:10 pm
From this reference, I arrived at this MWE, trying to scale the plot marks with the inverse of the third input table column. \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest, filter discard warning=false} \begin{document} \begin{tikzpicture} \begin{axis} [ point meta=explicit symbolic, scatter/@pre marker code/.style={/tikz/mark size=\pgfplotspointmeta}, scatter/@post marker code/.style={}, grid=major ] \addplot+ [scatter, only marks] table[col sep=comma,meta expr={(1/\thisrow{z})}] { x,y,z 1,1,1 1,2,2 2,1,3 2,2,4 }; \end{axis} \end{tikzpicture} \end{document} which produces the error Package PGF Math: Unknown operator `Y' or `Y1' (in '1Y1.0e0]') which seems to refer to the output format of the fpu library (source). How do I need to modify the code to make this work?
- Faulty lines appearing on plain colored tikz drawing if PDF converted to PNG on Overleafby Mr.Price on January 31, 2025 at 12:57 pm
I have the following latexmkrc to generate a png image of my file: END { system('convert -density 720 -flatten output.pdf graph.png'); } In most cases it works fine but now I have a problem with the following tikz drawing. While in editor it looks fine, in the png output it does not look the same -- any ideas what I can change and why is that the case? pdf output: png output: Fullcode: \documentclass{article} % Set operations illustrated with Venn diagrams % Author: Uwe Ziegenhagen % This is an expanded version of an example provided by T. Tantau \usepackage{tikz} \usepackage[active,tightpage]{preview} \PreviewEnvironment{tikzpicture} \usepackage[dvipsnames]{xcolor} \setlength\PreviewBorder{5pt}% \usetikzlibrary{shapes.geometric, arrows, positioning, calc, arrows.meta, backgrounds} \usepackage{pgfplots} \pgfplotsset{compat=1.11} \usepgfplotslibrary{fillbetween} \tikzset{background grid/.append style={step=1cm, ultra thin}} \begin{document} % Definition of circles \def\firstcircle{(0,0) circle (1.5cm)} \def\secondcircle{(0:2cm) circle (1.5cm)} \colorlet{circle edge}{Orange!50} \colorlet{circle area}{Orange!20} \tikzset{filled/.style={fill=circle area, draw=circle edge, thick}, outline/.style={draw=circle edge, thick}} \setlength{\parskip}{5mm} % Set A but not B \begin{tikzpicture}[show background grid] \begin{scope} \clip \firstcircle; \draw[filled, even odd rule] \firstcircle node {$A$} \secondcircle; \end{scope} \draw[outline] \firstcircle \secondcircle node {$B$}; \node[anchor=south] at (current bounding box.north) {$A \setminus B$}; \end{tikzpicture} \end{document} I tried to use the posted solution but it seems to damage the image - if you look closely, the font on second image looks worse than in the first
- How to connect nodes in a flowchartby Fatma Belabed on January 31, 2025 at 11:56 am
I wanted to draw this flowchart, but I couldn't connect the nodes correctly. this is my code: \tikzset{ arr/.style={thick,-stealth}} %%%%%%%%%%%%%%%%%%%%%%%% \usetikzlibrary{ arrows.meta, shapes, positioning, calc, decorations.markings} \tikzset{ block2/.style={ rectangle, draw, fill=white, rounded corners, text centered, text width = 14em, minimum height = 2em}, line/.style={draw, -Latex}} %%%%%%%%%%%%%%%%%%%%%%% \tikzset{ block/.style={ rectangle, draw, fill=blue!10, rounded corners, text centered, text width = 9em, minimum height = 2em}, line/.style={draw, -Latex}} \tikzset{ blockxx/.style={ rectangle, draw, fill=blue!10, text centered, text width = 9em, minimum height = 2em}, line/.style={draw, -Latex}} \tikzset{ blockx/.style={ rectangle, draw, fill=blue!10, rounded corners, text centered, text width = 6em, minimum height = 2em}, line/.style={draw, -Latex}} \tikzset{ block3/.style={ rectangle, draw, fill=blue!20, rounded corners, text centered, text width = 9em, minimum height = 2em}, line/.style={draw, -Latex}} \tikzset{ block4/.style={ rectangle, draw, fill=blue!50, rounded corners, text centered, text width = 9em, minimum height = 2em}, line/.style={draw, -Latex}} \tikzset{ block44/.style={ rectangle, draw, fill=blue!50, rounded corners, text centered, text width = 3em, minimum height = 2em}, line/.style={draw, -Latex}} \tikzset{ block444/.style={ rectangle, draw, fill=blue!50, rounded corners, text centered, text width = 8em, minimum height = 2em}, line/.style={draw, -Latex}} \begin{document} \begin{tikzpicture}[every node/.style={block}] \node [ block2, node distance=2cm] (second) {Security attacks}; \node[block3, below left=1cm and 1cm of second](case one) {Physical}; \node[block4, below = 1cm of second](case two) {Data Link}; \node[below right = 1cm and 1cm of second](case three) {Network}; \node[below right = 1cm and 5.5cm of second](case forr) {Transport}; \node[block3, below = 0.7cm of case forr](case forr1){Dos}; \node[block3, below = 0.7cm of case forr1](case forr2){Session hijacking}; \node[block3, below = 0.7cm of case forr2](case forr3){Exhaustion}; \node[below right = 1cm and 10cm of second](case five) {Application}; \node[block3, below = 0.7cm of case five](case five1){Dos}; \node[block3, below = 0.7cm of case five1](case five2){Repudiation}; \node[block3, below = 0.7cm of case five2](case five3){Deluge}; \node[block3, below = 0.7cm of case one](no info){Dos}; \node[block3, below = 0.7cm of no info](no info1){Eavesdropping}; \node[block3, below = 0.7cm of no info1](no info2){Jamming}; \node[block444, on grid,below = 1.7cm of case two](aa){Dos}; \node[block444, on grid, below = 1.5cm of aa](aa1){Collision}; \node[block444, on grid,below = 1.5cm of aa1](aa2){Unfairness}; \node[block444, on grid,below = 1.5cm of aa2](aa3){Exhaustion}; \node[block444, on grid,below = 1.5cm of aa3](aa4){Traffic monitoring}; \node[blockxx, on grid,below = 1.5cm of case three](a){Dos}; \node[blockxx, on grid,below = 1.5cm of a](a1){Hole}; \node[blockxx, on grid,below = 1.5cm of a1](a2){Selective forwarding}; \node[blockxx, on grid,below = 1.5cm of a2](a3){Sybil}; \node[blockxx, on grid,below = 1.5cm of a3](a4){Eavesdropping}; \node[blockxx, on grid,below = 1.5cm of a4](a5){Spoofing}; \node[blockxx, on grid,below = 1.5cm of a5](a6){Traffic analysis}; \draw[arr] (second.south) --++ (0,-5pt) -| (case one); % physique \draw[arr] (case one.west) --++ (0,-5pt) -- (no info.west); \draw[arr] (case one.west) --++ (0,-5pt) -- (no info1.west); \draw[arr] (case one.west) --++ (0,-5pt) -- (no info2.west); \draw[arr] (second.south) --++ (0,-5pt) -| (case two); % data \draw[arr] (case two.west) --++ (0,-5pt) |- (aa.west); \draw[arr] (case two.west) --++ (0,-5pt) |- (aa1.west); \draw[arr] (case two.west) --++ (0,-5pt) |- (aa2.west); \draw[arr] (case two.west) --++ (0,-5pt) |- (aa3.west); \draw[arr] (case two.west) --++ (0,-5pt) |- (aa4.west); \draw[arr] (second.south) --++ (0,-5pt) -| (case three); % network \draw[arr] (case three.west) --++ (0,-5pt) |- (a.west); \draw[arr] (case three.west) --++ (0,-5pt) |- (a1.west); \draw[arr] (case three.west) --++ (0,-5pt) |- (a2.west); \draw[arr] (case three.west) --++ (0,-5pt) |- (a3.west); \draw[arr] (case three.west) --++ (0,-5pt) |- (a4.west); \draw[arr] (case three.west) --++ (0,-5pt) |- (a5.west); \draw[arr] (case three.west) --++ (0,-5pt) |- (a6.west); \draw[arr] (second.south) --++ (0,-5pt) -| (case forr); % Transport \draw[arr] (case forr.west) --++ (0,-5pt) |- (case forr1.west); \draw[arr] (case forr.west) --++ (0,-5pt) |- (case forr2.west); \draw[arr] (case forr.west) --++ (0,-5pt) |- (case forr3.west); \draw[arr] (second.south) --++ (0,-5pt) -| (case five); % Application \draw[arr] (case five.west) --++ (0,-5pt) |- (case five1.west); \draw[arr] (case five.west) --++ (0,-5pt) |- (case five2.west); \draw[arr] (case five.west) --++ (0,-5pt) |- (case five3.west); \end{tikzpicture} \end{figure} \end{document} Thanks
- How to draw this closed contour diagram using TikZ?by Laura Olatex on January 31, 2025 at 6:08 am
This is a contour I encountered while working with contour integrals. First, I need to clarify that I have almost no knowledge of TikZ. I can only draw the following contour, but I am unable to improve it further in latex. Could you please guide me on how to add infinitely many branches to the diagram? I would greatly appreciate any hints or sketch code. I tried to draw the outlines below, in fact I have to explain again that I have almost no TikZ foundation, how can I add an infinite number of outlines as shown in the picture? code: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc,decorations.markings} \begin{document} \begin{tikzpicture} % Configurable parameters \def\gap{0.2} \def\bigradius{3} \def\littleradius{0.5} % Axes \draw [help lines,->] (-1.25*\bigradius, 0) -- (1.25*\bigradius,0); \draw [help lines,->] (0, -1.25*\bigradius) -- (0, 1.25*\bigradius); % Red path \draw[line width=1pt, decoration={ markings, mark=at position 0.2455 with {\arrow[line width=1.2pt]{>}}, mark=at position 0.765 with {\arrow[line width=1.2pt]{>}}, mark=at position 0.87 with {\arrow[line width=1.2pt]{>}}, mark=at position 0.97 with {\arrow[line width=1.2pt]{>}}}, postaction={decorate}] let \n1 = {asin(\gap/2/\bigradius)}, \n2 = {asin(\gap/2/\littleradius)} in (\n1:\bigradius) arc (\n1:360-\n1:\bigradius) -- (-\n2:\littleradius) arc (-\n2:-360+\n2:\littleradius) -- cycle; % The labels \node at (3.6,-0.2){$x$}; \node at (-0.24,3.53) {$iy$}; \node at (-0.6,0.43) {$\gamma_{\varepsilon}$}; \node at (-1.8,2.8) {$\gamma_{R}$}; \node at (1.9,0.29) {$l_1$}; \node at (1.555,-0.32) {$l_2$}; \end{tikzpicture} \end{document}
- How to properly make custom list for experience entries with imagesby DaniCee on January 31, 2025 at 4:22 am
I am redoing my CV in a more simplified way, and I want to create a list of experience entries that include the company logos under the employment dates. I want to accomplish this (mock-up): So far, I managed to write this MWE tweaking from my old CV: \documentclass{article} \usepackage[left=2cm, top=2cm, right=2cm, bottom=2cm]{geometry} \usepackage[quiet]{fontspec} \usepackage{tikz} \usepackage{lipsum} \setmainfont{Linux Libertine O} \setlength{\parindent}{0pt} \setlength{\parskip}{.5\baselineskip plus \smallskipamount minus \smallskipamount} %My list \setlength{\tabcolsep}{0pt} \newenvironment{entrylist}{% \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll} }{% \end{tabular*} } \newcommand{\entry}[4]{% #1&\parbox[t]{14cm}{% {\large \textbf{#2}}% \hfill% #3\\% #4\vspace{2\parsep}% }\\} \makeatletter \renewenvironment{entrylist}{% \par\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll} }{% \end{tabular*}\par } \makeatother \begin{document} \begin{entrylist} \entry {2020 - present} {Current position} {\smash{\raisebox{-0.75cm}{ \includegraphics[height=1.2cm]{example-image-a}}} } {\textbf{Company A}\\ The Department\\ \lipsum[1] } \entry {2018 - 2020} {Past position} {\smash{\raisebox{-0.75cm}{ \includegraphics[height=1.2cm]{example-image-b}}} } {\textbf{Company B}\\ Another Department\\ \lipsum[2] } \end{entrylist} \end{document} Which produces this: I am not sure how to bring the image down without overly complicating the code (probably arranging all the elements into tikzpicture nodes). Is there a straightforward way of accomplishing this? What would be more correct to use here: itemize, tabular, tikzpicture? I have no preference, just an elegant straightforward solution. Thanks!
- How to generate a dipole configuration?by Amr Khaled 202300246 on January 30, 2025 at 4:55 pm
Is there a LaTeX code that generates the dipole configuration in the picture, I tried very hard and didn't find any.
- How to Optimize a TikZ Animation of Quicksort?by Emanuele Nardi on January 22, 2025 at 3:11 pm
While revisiting some old notes on algorithms, I came across a code snippet illustrating the sorting of a vector using quicksort. I’m dissatisfied with how the nodes are defined relative to each other, requiring some nodes to be repeated to maintain references. Additionally, I had to draw them in reverse order to ensure the edges overlapped correctly. One potential optimization I considered is ensuring the "examining" styled node always displays \(i\) above it. How can I optimize the code to avoid repetition? % arara: pdflatex % arara: latexmk: { clean: partial } \documentclass[tikz, border=.2cm]{standalone} \usetikzlibrary{positioning} \tikzset{ vector/.style = { draw = black, rectangle, align = center, anchor = west, fill = yellow!40, font = \ttfamily\bfseries, minimum height = 0.7cm, minimum size = 0.7cm }, label/.style = { node distance = 0pt, font = \scriptsize, }, % cells styles undiscovered/.style = { fill = teal!20, draw = teal, dashed, }, examining/.style = { very thick, fill=teal!50, }, pivot/.style = { fill = purple!60, }, smallerPivot/.style = { fill = red!20, }, greaterPivot/.style = { fill = gray!20, draw = gray!80, dashed, }, } \begin{document} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 11, undiscovered] (10) {25}; \node[vector, left=-1pt of 10, undiscovered] (9) {21}; \node[vector, left=-1pt of 9, undiscovered] (8) {30}; \node[vector, left=-1pt of 8, undiscovered] (7) {12}; \node[vector, left=-1pt of 7, undiscovered] (6) {27}; \node[vector, left=-1pt of 6, undiscovered] (5) {15}; \node[vector, left=-1pt of 5, undiscovered] (4) {29}; \node[vector, left=-1pt of 4, undiscovered] (3) {28}; \node[vector, left=-1pt of 3, examining] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; % NOTE I have to repeat it otherwise I don't have the reference to node 2 for node 1 \node[vector, right=-1pt of 1, examining] (2) {14}; \node[label, above=of 2] (index-i) {\(i\)}; \node[label, below=of 1] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 11, undiscovered] (10) {25}; \node[vector, left=-1pt of 10, undiscovered] (9) {21}; \node[vector, left=-1pt of 9, undiscovered] (8) {30}; \node[vector, left=-1pt of 8, undiscovered] (7) {12}; \node[vector, left=-1pt of 7, undiscovered] (6) {27}; \node[vector, left=-1pt of 6, undiscovered] (5) {15}; \node[vector, left=-1pt of 5, undiscovered] (4) {29}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, right=-1pt of 2, examining] (3) {28}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 3] (index-i) {\(i\)}; \node[label, below=of 2] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 11, undiscovered] (10) {25}; \node[vector, left=-1pt of 10, undiscovered] (9) {21}; \node[vector, left=-1pt of 9, undiscovered] (8) {30}; \node[vector, left=-1pt of 8, undiscovered] (7) {12}; \node[vector, left=-1pt of 7, undiscovered] (6) {27}; \node[vector, left=-1pt of 6, undiscovered] (5) {15}; \node[vector, left=-1pt of 4, greaterPivot] (3) {28}; \node[vector, right=-1pt of 3, examining] (4) {29}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 4] (index-i) {\(i\)}; \node[label, below=of 2] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 11, undiscovered] (10) {25}; \node[vector, left=-1pt of 10, undiscovered] (9) {21}; \node[vector, left=-1pt of 9, undiscovered] (8) {30}; \node[vector, left=-1pt of 8, undiscovered] (7) {12}; \node[vector, left=-1pt of 7, undiscovered] (6) {27}; \node[vector, left=-1pt of 5, greaterPivot] (4) {29}; \node[vector, right=-1pt of 4, examining] (5) {15}; \node[vector, left=-1pt of 4, greaterPivot] (3) {28}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 5] (index-i) {\(i\)}; \node[label, below=of 2] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 11, undiscovered] (10) {25}; \node[vector, left=-1pt of 10, undiscovered] (9) {21}; \node[vector, left=-1pt of 9, undiscovered] (8) {30}; \node[vector, left=-1pt of 8, undiscovered] (7) {12}; \node[vector, left=-1pt of 6, greaterPivot] (5) {28}; \node[vector, right=-1pt of 5, examining] (6) {27}; \node[vector, left=-1pt of 5, greaterPivot] (4) {29}; \node[vector, left=-1pt of 4, smallerPivot] (3) {15}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 6] (index-i) {\(i\)}; \node[label, below=of 3] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 11, undiscovered] (10) {25}; \node[vector, left=-1pt of 10, undiscovered] (9) {21}; \node[vector, left=-1pt of 9, undiscovered] (8) {30}; \node[vector, left=-1pt of 7, greaterPivot] (6) {27}; \node[vector, right=-1pt of 6, examining] (7) {12}; \node[vector, left=-1pt of 6, greaterPivot] (5) {28}; \node[vector, left=-1pt of 5, greaterPivot] (4) {29}; \node[vector, left=-1pt of 4, smallerPivot] (3) {15}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 7] (index-i) {\(i\)}; \node[label, below=of 3] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 11, undiscovered] (10) {25}; \node[vector, left=-1pt of 10, undiscovered] (9) {21}; \node[vector, left=-1pt of 8, greaterPivot] (7) {29}; \node[vector, right=-1pt of 7, examining] (8) {30}; \node[vector, left=-1pt of 7, greaterPivot] (6) {27}; \node[vector, left=-1pt of 6, greaterPivot] (5) {28}; \node[vector, left=-1pt of 5, smallerPivot] (4) {12}; \node[vector, left=-1pt of 4, smallerPivot] (3) {15}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 8] (index-i) {\(i\)}; \node[label, below=of 4] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 11, undiscovered] (10) {25}; \node[vector, left=-1pt of 9, greaterPivot] (8) {30}; \node[vector, right=-1pt of 8, examining] (9) {21}; \node[vector, left=-1pt of 8, greaterPivot] (7) {29}; \node[vector, left=-1pt of 7, greaterPivot] (6) {27}; \node[vector, left=-1pt of 6, greaterPivot] (5) {28}; \node[vector, left=-1pt of 5, smallerPivot] (4) {12}; \node[vector, left=-1pt of 4, smallerPivot] (3) {15}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 9] (index-i) {\(i\)}; \node[label, below=of 4] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, undiscovered] (11) {13}; \node[vector, left=-1pt of 10, greaterPivot] (9) {21}; \node[vector, right=-1pt of 9, examining] (10) {25}; \node[vector, left=-1pt of 9, greaterPivot] (8) {30}; \node[vector, left=-1pt of 8, greaterPivot] (7) {29}; \node[vector, left=-1pt of 7, greaterPivot] (6) {27}; \node[vector, left=-1pt of 6, greaterPivot] (5) {28}; \node[vector, left=-1pt of 5, smallerPivot] (4) {12}; \node[vector, left=-1pt of 4, smallerPivot] (3) {15}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 10] (index-i) {\(i\)}; \node[label, below=of 4] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, greaterPivot] (10) {25}; \node[vector, right=-1pt of 10, examining] (11) {13}; \node[vector, left=-1pt of 10, greaterPivot] (9) {21}; \node[vector, left=-1pt of 9, greaterPivot] (8) {30}; \node[vector, left=-1pt of 8, greaterPivot] (7) {29}; \node[vector, left=-1pt of 7, greaterPivot] (6) {27}; \node[vector, left=-1pt of 6, greaterPivot] (5) {28}; \node[vector, left=-1pt of 5, smallerPivot] (4) {12}; \node[vector, left=-1pt of 4, smallerPivot] (3) {15}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 11] (index-i) {\(i\)}; \node[label, below=of 4] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, greaterPivot] (11) {28}; \node[vector, left=-1pt of 11, greaterPivot] (10) {25}; \node[vector, left=-1pt of 10, greaterPivot] (9) {21}; \node[vector, left=-1pt of 9, greaterPivot] (8) {30}; \node[vector, left=-1pt of 8, greaterPivot] (7) {29}; \node[vector, left=-1pt of 7, greaterPivot] (6) {27}; \node[vector, left=-1pt of 6, smallerPivot] (5) {13}; \node[vector, left=-1pt of 5, smallerPivot] (4) {12}; \node[vector, left=-1pt of 4, smallerPivot] (3) {15}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, pivot] (1) {20}; \node[label, above=of 11] (index-i) {\phantom{\(i\)}}; \node[label, below=of 5] (index-j) {\(j\)}; \end{tikzpicture} \begin{tikzpicture} \node[vector, greaterPivot] (11) {28}; \node[vector, left=-1pt of 11, greaterPivot] (10) {25}; \node[vector, left=-1pt of 10, greaterPivot] (9) {21}; \node[vector, left=-1pt of 9, greaterPivot] (8) {30}; \node[vector, left=-1pt of 8, greaterPivot] (7) {29}; \node[vector, left=-1pt of 7, greaterPivot] (6) {27}; \node[vector, left=-1pt of 6, pivot] (5) {20}; \node[vector, left=-1pt of 5, smallerPivot] (4) {12}; \node[vector, left=-1pt of 4, smallerPivot] (3) {15}; \node[vector, left=-1pt of 3, smallerPivot] (2) {14}; \node[vector, left=-1pt of 2, smallerPivot] (1) {13}; \node[label, above=of 11] (index-i) {\phantom{\(i\)}}; \node[label, below=of 5] (index-j) {\(j\)}; \end{tikzpicture} \end{document}
- How to recreate "old style" graphs [closed]by Walterminator-58 on December 14, 2024 at 4:53 pm
How to recreate this graph identically with the same style and font ? KR, W-58.
- How to build the 3d cartesian coordinate system like this and add this graphby sukmudmaisus on March 31, 2024 at 5:42 pm
When I used the pgfplots or tikz3d I have a problem that the x,y,z axis doesn't like this. They always incline from it should be like the below image. How to set the x,y,z axis that x-axis is towards to the observer click to this link for information.
- Diagnosing Standalone and Gensymb conflictby Altissimo on January 9, 2024 at 5:52 pm
Disclaimer: I am new-ish to LaTeX, and self-taught. I am trying to make a "Unit Circle" TikZ graphic, in which I would like to have the \degree symbol from the gensymb package in the label text of a node. My current workflow involves the standalone package, and uses the \include command to create a sort of "master file" containing each of my creations on its own page which I reference in other Overleaf projects using the 'output file from another project' and the graphicx package to reduce compile time. There is probably a better way to do this, but it keeps it simple enough for me and I like having everything in more or less the same place so I can make quick references between my images. It has worked so far, until now... My problem is, it is preferable if I don't have to update the preamble of my master document every time I add a new picture, especially since that's where I define things like colors which occasionally use identical names (e.g. gradient1). Hence, I load \usepackage[subpreambles]{standalone} to read the preamble of each standalone separately. Again, this has worked well enough so far that I have been able to solve any hiccups myself. I have failed to diagnose why exactly, but there is something going on with the [subpreambles] tag and loading the gensymb package. Here is my MWE: \documentclass[tikz]{standalone} \usepackage{textcomp,gensymb} % for degree symbol \begin{document} \begin{tikzpicture} \node at (0,0) {$0\degree$}; \end{tikzpicture} \end{document} which I have in Overleaf as degree-test.tex. When I try to reference this file in another: \documentclass[tikz]{standalone} \usepackage[subpreambles]{standalone} \begin{document} \include{degree-test} \end{document} I get the error: Package standalone Warning: Sub-preamble of file 'degree-test.tex' has changed. Content will be ignored. Please rerun LaTeX! on input line 4. I compile with LuaLaTeX, but other compilers produce similar results. Even removing \degree from the node label produces the error, despite not actually using the symbol. There must be some kind of conflict with commands which define certain things during the preamble, but I don't know how to read the error logs and they're very frightening on the surface. Is there a simple fix for this? EDIT: I have also disqualified \documentclass[tikz]{standalone} and \include vs \includestandalone as culprits.
- Dynamic tikz bar plot from JSON databy Almic7 on July 18, 2021 at 3:51 pm
I have JSON file that looks something like this { "data": [ { "type": "SENIOR", "male": 350000.0, "female": 225000.0 }, { "type": "ENTRY", "male": 100000.0, "female": 40000.0 }, { "type": "MID", "male": 225000.0, "female": 150000.0 } ] } and I need to create a bar plot with dynamic x fields, that are read from json. \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{luacode} \usepackage{tikz} \usepackage{pgfplots} \usepackage{ifthen} %%%%% Lua code %%%%%% \begin{luacode} local json = require("json") local file = io.open("mwe.json") tab = json.parse(file:read("*all")) file:close() \end{luacode} \begin{document} % Number of labels \newcommand{\nrlabels}{\directlua{tex.print(table.getn(tab['data']))}} % Create counter for loop through labels \newcounter{labelctr}\stepcounter{labelctr} \newcounter{totallabels} \setcounter{totallabels}{\nrlabels}\stepcounter{totallabels} \newcounter{onemorelabel}\setcounter{onemorelabel}{\value{totallabels}}\addtocounter{onemorelabel}{-1} \begin{tikzpicture} \begin{axis}[ width = 0.85*\textwidth, height = 8cm, %major x tick style = transparent, ybar=2*\pgflinewidth, bar width=20pt, %ymajorgrids = true, ylabel = {Average Wage}, %symbolic x coords= {\whiledo{\value{labelctr} < \value{totallabels}}{\directlua{tex.print(tab['data'][\thelabelctr]['type'])}\ifthenelse{\value{labelctr}<\value{onemorelabel}}{,}{}\stepcounter{labelctr}}} symbolic x coords={SENIOR,ENTRY,MID} ] \addplot[fill=blue] coordinates {\whiledo{\value{labelctr} < \value{totallabels}}{(\directlua{tex.print(tab['data'][\thelabelctr]['type'])}, \directlua{tex.print(tab['data'][\thelabelctr]['male'])}) \stepcounter{labelctr}}}; \end{axis} \end{tikzpicture} \end{document} This is what I have so far. And I need something like this Thanks..
- tikzmark not known by TeX Studioby Isi on June 19, 2020 at 8:37 am
I was wondering if there was an update or something like that in the tikz package, since the tikzlibrary tikzmark is not known by my TeX editor (TeX Studio) . Here are my imports: %\documentclass[11pt]{beamer} \documentclass[handout,11pt]{beamer} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[english]{babel} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{eucal} \usepackage{amssymb} \usepackage{bm} \usepackage{graphicx} \usetheme{Madrid} % tikz \usepackage{tikz} \usetikzlibrary{arrows,3d,matrix,calc} \usetikzlibrary[matrix] \usetikzlibrary{plotmarks} \usepackage{pgf} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepgfplotslibrary{groupplots} \usepgfplotslibrary{dateplot} % for writing vectors, matrices, tensors in tables \tikzset{ matrixstyle/.style={ matrix of nodes, draw, nodes in empty cells, column sep = -\pgflinewidth, row sep = -\pgflinewidth, inner sep = -\pgflinewidth, nodes={% inner sep=0,outer sep=0, draw, anchor=center, fill=white, minimum width=0.7cm, minimum height=0.7cm } }} \usetikzlibrary{tikzmark,positioning} \usepackage{tikzsymbols} and here you see, how these imports look in Tex Studio. You can see that the tikzmark library is unkown (the text when placing the mouse on it means: "key not recognized in the options"). I was wondering why this is the case. I am not 100% sure but I think this happened when I updated all my packages with MikTex, before it was known. Still, the command works. This is confusing for me.
- TikZ: text along path as node (again)by Tashi Walde on January 20, 2020 at 9:27 am
I would like to ask again the following question: TikZ: text along path as node That question was answered with a solution which was good enough for OP at the time. I would, however like to have an answer to the question as posed originally. More specifically, I want to have a text following a curved path (for instance using decorations) and then use that text to fit a shape around it. In this example, I would like to draw an ellipse fitting "stuff" and "along path" but I don't know how to refer to "along path" because it has no node name. \documentclass{standalone} \usepackage{pgf,tikz} \usetikzlibrary{decorations.text,fit,shapes} \begin{document} \begin{tikzpicture} \node (A) at (-2,2) {stuff}; \draw[postaction={decorate,decoration={ text along path, text={along path}, % name = (B), <--- this does not work raise = 3 }}] (-1,0) to [out= 90, in=90] (1,0); % \draw[fit=(A)(B), ellipse]{}; <---- I want to be able to do this \end{tikzpicture} \end{document}
- Simpler solution of "Table cell color overlaps cell border"?by fairytale on February 19, 2017 at 2:31 pm
I have seen many discussions about "Table cell color overlaps cell border". I want to share my try on this problem. Also, I am a beginner in latex, my code may not be the best, I would like to see if there is any better solution. Some said that it is the problem of pdf viewer. I don't agree, because the cellcolor is really "bigger" than the cell. Some said that we can make the border thicker, but I think it make my tables look strange, so I don't want to use it. On the other hand, the \hhline solution cannot help much. Colored tables and cline/hhline The lines still disappear. I started to use tikz matrix to draw tables. The cellcolor is perfect and will not overlap any cell border. However, there are some disadvantages. The tikz picture is in a box. (i'm not very sure) The box caused indentations and overfull hbox. I need to use trimbox to correct the position of the table. Every cell has different size according to the contents inside them, you need to set a minimum height/width to make your table display properly. You need to find the best value by "trial and error". Making multicolumn/multirow is difficult. You need to use a parbox to insert the content into the cell, also, you need to find the best position of parbox by "trial and error" too. It is difficult to make line break too. You need to set the textwidth of the cell to make linebreak. Here is the MWE. \documentclass{article} \usepackage{tikz} \usetikzlibrary{matrix,positioning,backgrounds,fit} \tikzset{no right/.style={ draw=none, append after command={ [shorten <= -0.5\pgflinewidth] (\tikzlastnode.north east) edge(\tikzlastnode.north west) ([shift={( 0.5\pgflinewidth,-0.5\pgflinewidth)}]\tikzlastnode.north west) edge([shift={( 0.5\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south west) ([shift={( 0.5\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south west) edge([shift={(-1.0\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south east) } } } \tikzset{no left/.style={ draw=none, append after command={ [shorten <= -0.5\pgflinewidth] (\tikzlastnode.north east) edge(\tikzlastnode.north west) ([shift={( -0.5\pgflinewidth,0.5\pgflinewidth)}]\tikzlastnode.north east) edge([shift={( -0.5\pgflinewidth,0.5\pgflinewidth)}]\tikzlastnode.south east) ([shift={( 0.5\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south west) edge([shift={(-1.0\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south east) } } } \tikzset{no left right/.style={ draw=none, append after command={ [shorten <= -0.5\pgflinewidth] (\tikzlastnode.north east) edge(\tikzlastnode.north west) ([shift={( 0.5\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south west) edge([shift={(-1.0\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south east) } } } \begin{document} \begin{tikzpicture}[cell/.style={rectangle,draw=black},nodes in empty cells] \matrix (m) [ matrix of nodes, row sep=-\pgflinewidth, column sep=-2\pgflinewidth, nodes={anchor=center,text height=2ex,text depth=0.25ex}, column 1/.style = {nodes={cell, minimum width=1cm}}, column 2/.style = {nodes={cell, minimum width=2cm}}, column 3/.style = {nodes={cell, minimum width=2cm}}, row 1/.style={nodes={cell,fill=black!25!white}}, row 2/.style={nodes={cell}}, row 3/.style={nodes={cell}}, row 4/.style={nodes={cell}}, ] { & 2 & 3 \\ |[no right,fill=black!25!white]| & |[no left right,draw=none,fill=black!25!white]| & |[no left,fill=black!25!white]| \\ 2 & c & d \\ 3 & & e \\ }; \node[fit=(m-2-1)(m-2-3)]{\parbox[c][2.5em][b]{5cm}{\centering green cell long}}; \end{tikzpicture} \end{document} All borders can be seen at any zoom level. The above code is based on: Cut one side of a rectangle node in TikZ Borders of a matrix are not well placed My question is : Is there any simpler way to draw "perfect table"? (i.e, Table cell color will not overlap cell border.)
- How to incorporate and scale matplotlib plots in latex using the PGF backend?by Nils_M on September 20, 2013 at 3:09 pm
I am using the pgf backend of matplotlib to generate pgf files which I want to put into my latex document using tikzscale to be able to resize them easily. Example python code: #!/usr/bin/env python # -*- coding: utf-8 -*- import matplotlib as mpl mpl.use('pgf') import numpy as np import matplotlib.pyplot as mplp mpl.rcParams['text.latex.unicode']=True mpl.rcParams['text.usetex']=True mpl.rcParams['pgf.texsystem'] = 'pdflatex' fig = mplp.figure() ax = fig.add_subplot(111) x = np.arange(0,2 * np.pi, .1) data = np.sin(x) fmt = {"lw" : 3, "c" : "r", "ls" : '-'} ax.plot(x, data, label=r"sample data with greek $\mu$", **fmt) ax.set_ylabel(r"sample", rotation=0) ax.legend() fig.set_size_inches(1.41,1.) # fig.savefig('./sample.pgf', dpi=500, bbox_inches='tight') fig.savefig('./sample.pgf', dpi=500) Example latex code: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{tikz} \usepackage{tikzscale} \usepackage{pgfplots} \pgfplotsset{compat=1.8} \newcommand{\includepgf}[4] { \begin{figure} \centering \includegraphics{#1} \includegraphics[width=#2\textwidth, height=#2*0.7071428571428572\textwidth]{#1} \includegraphics[width=#2\textwidth, axisratio=0.7071428571428572]{#1} \caption[]{#4} \label{#3} \end{figure} } \begin{document} \includepgf{sample.pgf}{.9}{fig:sample}{Sample Figure} \end{document} Unfortunately the following happens for the three different \includegraphics commands: Works as expected, includes plot in original size Compiles with Package tikzscale Warning: Scaling of sample.pgf's width was only (tikzscale) accurate to 208.59694pt on input line 27. Package tikzscale Warning: Scaling of sample.pgf's height was only (tikzscale) accurate to 147.29488pt on input line 27. no resizing in final pdf file. Does not compile, gives ! Package tikzscale Error: Requested to scale unscalable graphic.
- \pause in tikzpicture breaks footlineby Bristol on June 24, 2011 at 9:05 am
I've discovered that you can \pause within a tikzpicture, which works well until I switched the theme to one with a footline. I've created a "test case" that illustrates the problem. \documentclass{beamer} \providecommand\thispdfpagelabel[1]{} % Not sure what this does but our installation requires it. \usepackage{tikz} \usetheme{Madrid} % Has a footline. \begin{document} \begin{frame} \frametitle{test} \begin{tikzpicture} \node at (0, 1) {Hello}; \pause \node at (0, 0) {World}; \end{tikzpicture} \end{frame} \end{document} This creates two slides, but the footline is only drawn on the second (the headline/title appears on both). Is there anything I can do about this?