TikZ
- How to plot the graph with better curvature?by user1942348 on August 22, 2026 at 5:44 pm
I want to plot the above Fig. Using the code below, the curvature are not coming same as the Fig. Please help me get the exact Fig. \documentclass[12pt]{article} \usepackage{tikz} \begin{document} \begin{center} \begin{tikzpicture}[ scale=1.5, thick, vertex/.style={circle, draw=black, fill=white, inner sep=1.5pt, minimum size=6pt} ] % Coordinates \coordinate (v2) at (0, 0); \coordinate (v1) at (-1.5, 0.6); \coordinate (v3) at (1.5, 0.6); \coordinate (v7) at (-1.5, -0.6); \coordinate (v6) at (1.5, -0.6); \coordinate (v8) at (-2.5, 0); \coordinate (v5) at (2.5, 0); \coordinate (v0) at (-3.5, 1.8); \coordinate (v4) at (3.5, 1.8); \coordinate (v10) at (-3.5, -1.8); \coordinate (v9) at (3.5, -1.8); % Continuous Curves % Curve 1: Inner (v0 -> v1 -> v2 -> v3 -> v4) \draw (v0) to[out=-30, in=150] (v1) to[out=-30, in=180] (v2) to[out=0, in=210] (v3) to[out=30, in=210] (v4); % Curve 2: Inner (v10 -> v7 -> v2 -> v6 -> v9) \draw (v10) to[out=30, in=210] (v7) to[out=30, in=180] (v2) to[out=0, in=150] (v6) to[out=-30, in=150] (v9); % Curve 3: Top (v8 -> v1 -> v3 -> v5) \draw (v8) to[out=45, in=210] (v1) to[out=30, in=150] (v3) to[out=-30, in=135] (v5); % Curve 4: Bottom (v8 -> v7 -> v6 -> v5) \draw (v8) to[out=-45, in=150] (v7) to[out=-30, in=210] (v6) to[out=30, in=225] (v5); % Curve 5: Left Bow (v0 -> v8 -> v10) \draw (v0) to[out=-60, in=90] (v8) to[out=-90, in=60] (v10); % Curve 6: Right Bow (v4 -> v5 -> v9) \draw (v4) to[out=-120, in=90] (v5) to[out=-90, in=120] (v9); % 3. Hollow Nodes \node[vertex, label=left:$v_0$] at (v0) {}; \node[vertex, label=above:$v_1$] at (v1) {}; \node[vertex, label=above:$v_2$] at (v2) {}; \node[vertex, label=above:$v_3$] at (v3) {}; \node[vertex, label=right:$v_4$] at (v4) {}; \node[vertex, label=right:$v_5$] at (v5) {}; \node[vertex, label=below:$v_6$] at (v6) {}; \node[vertex, label=below:$v_7$] at (v7) {}; \node[vertex, label=left:$v_8$] at (v8) {}; \node[vertex, label=right:$v_9$] at (v9) {}; \node[vertex, label=left:$v_{10}$] at (v10) {}; \end{tikzpicture} \end{center} \end{document}
- Curve sketching in LaTeX documentby M.R. Yegan on August 21, 2026 at 4:13 pm
I wish to sketch a math graph in Latex Doc. my windows is 8.1 64 bit operating system. we need two packages tikz and pgf. I did not find these packages compatible with windows 8.1. Any help will be appreciated.
- How to create a macro to be concatenated?by D G on August 21, 2026 at 5:13 am
The macro \PointLabel is made to simplify creating label on a graph. \fill \PointLabel[above]{-2} \PointLabel[below]{-1} ; Here below is the full code: \documentclass[tikz,border=1cm,12pt]{standalone} \usepackage{amsmath} \usepackage{xintexpr} \newcommand\fx[1]{(#1)^2} \newcommand{\Rational}[1]{% \xintifboolexpr{\xinttheexpr (#1)<0\relax} {-\xintTeXFrac{\xinttheexpr reduce(-( #1 ))\relax}} {\xintTeXFrac{\xinttheexpr reduce(#1)\relax}} } \newcommand{\CoordLabel}[1]{$\left(\Rational{#1},\Rational{\fx{#1}}\right)$} \newcommand{\PointLabel}[2][]{(#2,{\fx{#2}}) circle (2pt) node[#1]{\CoordLabel{#2}}} \begin{document} \begin{tikzpicture}[scale=1.2] \draw[->] (-3.5,0)--(3.5,0) node[right] {$x$}; \draw[->] (0,-1)--(0,10) node[above] {$y$}; \draw[blue,thick,samples=20,domain=-3:3] plot(\x,{\fx{\x}}); \fill (0,{\fx{0}}) circle(2pt) node[below right,red]{\CoordLabel{0}} (1,{\fx{1}}) circle(2pt) node[right]{\CoordLabel{1}} (2,{\fx{2}}) circle(2pt) node[right]{\CoordLabel{2}} (2.5,{\fx{2.5}}) circle(2pt) node[right]{$y=f(x)$} ; % the following causes errors. \fill \PointLabel[above]{-2} \PointLabel[below]{-1} ; \end{tikzpicture} \end{document} However it produces errors: ! Package tikz Error: Giving up on this path. Did you forget a semicolon?. See the tikz package documentation for explanation. Type H <return> for immediate help. ... l.40 \PointLabel [above]{-2} ?
- How to create a dynamic fan in TikZ in LaTeX?by mathrm alpha on August 18, 2026 at 5:49 am
Although I've created a basic fan shape in TikZ, how do I make the center blade of the TikZ fan dynamic rotate? the value you enter determines exactly how fast the TikZ fan I created will spin. \documentclass{article} \usepackage{tikz} \usepackage[paperwidth=9cm, paperheight=9cm, margin=1.5cm]{geometry} \begin{document} \pagestyle{empty} \begin{figure}[htbp] \begin{tikzpicture} \filldraw[color=yellow!60, fill=orange!40, very thick](0,0) circle (3); \filldraw[color=yellow!60, fill=red!0, very thick](0,0) circle (2.5); \begin{scope}[rotate=0] \draw [line width=0.3cm] (0,0) -- (2,2); \draw [line width=0.3cm] (0,0) -- (0,3); \draw [line width=0.3cm] (0,0) -- (-2,2); \draw [line width=0.3cm] (0,0) -- (2,-2); \draw [line width=0.3cm] (0,0) -- (3,0); \draw [line width=0.3cm] (0,0) -- (-3,0); \draw [line width=0.3cm] (0,0) -- (0,-3); \draw [line width=0.3cm] (0,0) -- (-2,-2); \filldraw[orange] (0,0) circle (30pt) node[anchor=west]{}; \end{scope} \end{tikzpicture} \end{figure} \end{document}
- My goal is to approximate an arc length reparameterizationby Jasper on August 16, 2026 at 9:51 pm
My goal is to approximate an arc length reparameterization. The thick curve and the red curve should nearly coincide is the expected result. \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{mathtools} \usepackage{unicode-math} \tikzset{ declare function={ alpha(\t)=1/\t; dalpha(\t)=(alpha(\t+0.02)-alpha(\t-0.02))/0.04; length(\x,\y)=sqrt((\x)^2+(\y)^2); ldalpha(\t)=length(1,dalpha(\t)); } } \pgfmathdeclarefunction{riemannsumldalpha}{3}{% \pgfmathsetmacro{\count}{0}% \pgfmathsetmacro{\dx}{(#2-#1)/#3}% \pgfplotsinvokeforeach{1,...,#3} {% \pgfmathsetmacro{\count}{\count+ldalpha(#1+##1*\dx)*\dx}% }% \let\pgfmathresult\count% } \pgfmathdeclarefunction{inverseriemannsumldalpha}{4}{% \pgfmathsetmacro{\lo}{#2}% \pgfmathsetmacro{\hi}{#3}% \pgfplotsinvokeforeach{1,...,#4}{% \pgfmathsetmacro{\mid}{(\lo+\hi)/2}% \pgfmathsetmacro{\value}{riemannsumldalpha(0.25,\mid,#4)}% \pgfmathsetmacro{\test}{\value < #1}% \ifnum\test=1 \pgfmathsetmacro{\lo}{\mid}% \else \pgfmathsetmacro{\hi}{\mid}% \fi }% \pgfmathsetmacro{\pgfmathresult}{(\lo+\hi)/2}% } \tikzset{ declare function={ alphainverseriemannsumldalpha(\t,\s,\e,\sam)=alpha( inverseriemannsumldalpha(\t,\s,\e,\sam) ); } } \begin{document} Let \(\alpha(t)=1/t\). My goal is to approximate an arc length reparameterization. I believe that plotting the following composition will achieve this; \[\alpha\Biggl(\biggl(\int_{t_0}^t\lvert\alpha'(t)\rvert\,dt\biggr)^{-1}\Biggr).\] \begin{center} \begin{tikzpicture}[samples=5] % producing the expected result \draw[red] plot[domain=0.25:4] (\x,{alpha(\x)}); \draw[green] plot[domain=0.25:4] (\x,{dalpha(\x)}); \draw[blue] plot[domain=0.25:4] (\x,{ldalpha(\x)}); \draw[purple] plot[domain=0.25:4] (\x,{riemannsumldalpha(0.25,\x,7)}); \draw[yellow] plot[domain=0.25:4] (\x,{inverseriemannsumldalpha(\x,0.25,4,7)}); % not producing the expected result \draw[thick] plot[domain=0.25:4] (\x,{alphainverseriemannsumldalpha(\x,0.25,4,7)}); \end{tikzpicture} \end{center} \end{document}
- Triangle Nesting ( Similar to Sierpinski Triangles ) [duplicate]by Discrete on August 15, 2026 at 7:09 pm
Im curious to know if there is a more efficient way to have triangles repeat themselves in one another without needing to run the \draw command for each line of the triangle; similar to Sierpinski's triangles is essentially what it is but in a different way for nesting. So far i've been doing the \draw command as such \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} [scale = 3] \draw[thick] (0,0) -- (2,0) -- (1,1.73205) -- cycle; \draw[thick] (0,0) -- (1,0.8) (2,0) -- (1,0.8) -- (1,1.73205) -- (1,0.8); \draw[thick] (1,0.8) -- (1.566667,0.769); \end{tikzpicture} \end{document} Ive provided an example above of what it should look like however I need to define what the colors mean and some rules it has. Meaning of Colors: Black = 1st Generation triangles, Blue = 2nd Generation triangles, and Red = 3rd Generation triangles as well each generation has a specific intersection where all the points meet ( for example black has a intersection in the middle where all points meet ) I should also say that each generation has its own "sub section" where the rule above applies to each sub section and these sub sections are divided by the lines of the previous generation. ( for example a 3rd generation sub section can have a different intersection than another 3rd generation sub section this is so each has one intersection which will for the sake of simplicity be set in the center for all generations) if you have any questions on this to better help me feel free to ask and I apologize if some of it seems confusing it is a rather "niche" section of discrete geometry relating to triangles and other two dimensional shapes ( side note i'd like this concept to be done with other two dimensional shapes as well so if theres a way to set the starting shape to say a circle or another shape that would be amazing; and it would follow the same rules I have revealed here).
- Showcase of beautiful 'electrical circuit diagrams' done in TeX & friendsby cis on January 27, 2026 at 7:03 am
When I saw this thread How to customize CircuiTikz ac - dc symbols or this one Showcase of beautiful typography done in TeX & friends, I had the idea to add a showcase for electrical circuit diagrams. The package would typically be circuitikz. Feel free to post your large, small, or elegant circuit diagrams here in the community wiki. (I will also add some examples occasionally.) Attach your codes (if possible); this would be a great opportunity to learn from your coding and your style. \documentclass[margin=5pt, multi=circuitikz]{standalone} \usepackage{circuitikz} \begin{document} \begin{circuitikz}[european resistors] \draw[] (0,0) to[R=$R_1$, a_=$1\Omega$, name=R1, invert] (3,0); \end{circuitikz} \end{document}
- Shading young tableauby nick hristov on December 11, 2024 at 4:44 am
EDIT: Following Jasper Habicht's answer https://tex.stackexchange.com/a/732655/308324 , This code works well for all cells (you may need to fine tune the varuiables, which is annoying but doable) \newcommand{\shadehalf}[3]{% \raisebox{0pt}[0pt][0pt]{% \begin{tikzpicture}[baseline=1, scale=0.8] % Hardcoded coordinates \def\leng{0.65} % Rectangle side length \def\xone{0} % Rectangle x1 \def\yone{-0.16} % Rectangle y1 % Use \pgfmathsetmacro for calculating \xtwo and \ytwo \pgfmathsetmacro{\xtwo}{\xone + \leng} % Rectangle x2 \pgfmathsetmacro{\ytwo}{\yone + \leng} % Rectangle y2 % Draw the shapes \fill[#1] (\xone,\yone) rectangle (\xtwo,\ytwo); % Full square with first color \fill[#2] (\xone,\yone) -- (\xtwo,\yone) -- (\xtwo,\ytwo) -- cycle; % Half-shading triangle % Centered text \node at ({(\xtwo+\xone)/2},{(\yone+\ytwo)*0.6}) {#3}; \end{tikzpicture}% } } I am struggling to make a diagonal shading in Young tableaux. For example in the following: \documentclass{article} \usepackage{ytableau} \usepackage{graphicx} % For \scalebox \begin{document} \begin{ytableau} % line 1 *(green) 1 & *(red) 1& *(green) 1 \\ % line 2 \none& *(green) 1 & *(red) 1\\ % line 3 \none & \none & *(green) 1 \end{ytableau} \end{document} which produces I want to have diagonal shading in each boxes as in 1. TikZ: Rectangle with diagonal fill (two colors) \documentclass[tikz, margin=3mm]{standalone} \usetikzlibrary{shadows,shadings,shapes.symbols} \tikzset{ double color fill/.code 2 args={ \pgfdeclareverticalshading[% tikz@axis@top,tikz@axis@middle,tikz@axis@bottom% ]{diagonalfill}{100bp}{% color(0bp)=(tikz@axis@bottom); color(50bp)=(tikz@axis@bottom); color(50bp)=(tikz@axis@middle); color(50bp)=(tikz@axis@top); color(100bp)=(tikz@axis@top) } \tikzset{shade, left color=#1, right color=#2, shading=diagonalfill} } } \begin{document} \begin{tikzpicture}[my node/.style={ double color fill={green}{blue}}] \node[my node, shading angle=45]{}; \end{tikzpicture} \end{document} I think Staircase paths through young tableaux should be helpful but I fail to do what I want. I will appreciate any help. Thank you
- what would be the best way to wire these without it looking like a mess? (circuitikz)by Nate3384 on May 29, 2024 at 3:46 pm
simply doing it this way results in an unreadable mess, as you can see in the picture following it, I want to know if there's a better way of doing it without changing the pin order of the XNN components. \documentclass{article} \usepackage{circuitikz} \begin{document} \begin{circuitikz} % Define positions for the w, x, y, z labels \node (label_w) at (-4, 1.5) {$w$}; \node (label_x) at (-4, 0.5) {$x$}; \node (label_y) at (-4, -0.5) {$y$}; \node (label_z) at (-4, -1.5) {$z$}; \node [muxdemux, muxdemux def={NL=4, NR=1, NB=0, w=3, square pins=0, Lh=6, Rh=6}, rotate=0](A) at (0,2) {\rotatebox{0}{\small \ttfamily XNN}}; \node[above] at (A.lpin 1) {$x$}; \node[above] at (A.lpin 2) {$y$}; \node[above] at (A.lpin 3) {$z$}; \node[above] at (A.lpin 4) {$w$}; \node [muxdemux, muxdemux def={NL=4, NR=1, NB=0, w=3, square pins=0, Lh=6, Rh=6}, rotate=0](B) at (0,-2) {\rotatebox{0}{\small \ttfamily XNN}}; \node[above] at (B.lpin 1) {$z$}; \node[above] at (B.lpin 2) {$w$}; \node[above] at (B.lpin 3) {$x$}; \node[above] at (B.lpin 4) {$y$}; \node [muxdemux, muxdemux def={NL=4, NR=1, NB=0, w=3, square pins=0, Lh=6, Rh=6}, rotate=0](C) at (5,0) {\rotatebox{0}{\small \ttfamily XNN}}; \node[left] at (C.lpin 1) {\scriptsize XNN$\left(x,y,z,w\right)$}; \node[left] at (C.lpin 2) {\scriptsize XNN$\left(z,w,x,y\right)$}; \node[above] at (C.lpin 3) {$0$}; \node[above] at (C.lpin 4) {$0$}; \node[above] at (C.rpin 1) {$F$}; \begin{scope} \draw[draw opacity=0.4] (A.rpin 1) -| ([xshift=-1cm]C.lpin 1) |- (C.lpin 1); \draw[draw opacity=0.4] (B.rpin 1) -| ([xshift=-1cm]C.lpin 2) |- (C.lpin 2); \end{scope} % Wire from labels w,x,y,z to A and B pin's \draw (label_w) -- ++(0.5,0) |- (A.lpin 4); \draw (label_w) -- ++(0.5,0) |- (B.lpin 2); \draw (label_x) -- ++(0.75,0) |- (A.lpin 1); \draw (label_x) -- ++(0.75,0) |- (B.lpin 3); \draw (label_y) -- ++(1,0) |- (A.lpin 2); \draw (label_y) -- ++(1,0) |- (B.lpin 4); \draw (label_z) -- ++(1.5,0) |- (A.lpin 3); \draw (label_z) -- ++(1.5,0) |- (B.lpin 1); \end{circuitikz} \end{document}
- Nested tableauxby eti902 on February 1, 2024 at 5:32 am
EDIT : I added some examples to illustrate what I want to do. I would like to be able to draw nested Young tableaux. For a definition of Young tableaux, see https://en.wikipedia.org/wiki/Young_tableau. What I mean by nested is that the content of a cell of a tableau is itself a tableau. For example, my result should look like this : In general, rows and columns can be of any length. Here is another example to illustrate what I want to be able to do: Because I also want tabloids and column-tabloids, I draw my tableaux using the method in this answer (instead of the packages ytableau or genyoungtabtikz) : column tabloids versus row tabloids However, I am not used to tikz, and it does not work as I would like. There is a minimal code for my first example (I used \Tableau and \PTableau so that the computer does not confuse both methods): \documentclass{article} \usepackage{tikz} \newcount\tableauRow\newcount\tableauCol \newcommand\Tableau[2]{% \begin{tikzpicture}[scale=#2,draw/.append style={thick,black},baseline=-4mm] \tableauRow=0 \foreach \Row in {#1} { \tableauCol=1 \foreach\k in \Row { \draw(\the\tableauCol,\the\tableauRow)+(-.5,-.5)rectangle++(.5,.5); \draw(\the\tableauCol,\the\tableauRow)node{\k}; \global\advance\tableauCol by 1 } \global\advance\tableauRow by -1 } \end{tikzpicture} } \newcommand\PTableau[2]{% \begin{tikzpicture}[scale=#2,draw/.append style={thick,black},baseline=-4mm] \tableauRow=0 \foreach \Row in {#1} { \tableauCol=1 \foreach\k in \Row { \draw(\the\tableauCol,\the\tableauRow)+(-.5,-.5)rectangle++(.5,.5); \draw(\the\tableauCol,\the\tableauRow)node{\k}; \global\advance\tableauCol by 1 } \global\advance\tableauRow by -1 } \end{tikzpicture} } \begin{document} \[ \PTableau{{\Tableau{{1,2},{3,4}}{0.5},\Tableau{{5,6},{7,8}}{0.5}}}{1.5} \] \end{document} With this code, the result looks like this instead of what I want (I drew it because of computer problem, but it illustrates the problem): What should I modify to \PTableau so that I obtain the result I want? And mostly, why?
- TikZ text node and edge position in TikZitby Qohelet on November 27, 2023 at 5:46 pm
I am using the TikZit application to construct a diagram containing nodes that "contain" or "consist of" only text (formatted with color, etc.) and that are connected by various edges. When inputing the text as the label argument, the connecting edge encroaches into the middle of the text, like this: Here is the source code generated by TikZit: \begin{tikzpicture} \begin{pgfonlayer}{nodelayer} \node [style=none] (0) at (-2.5, 7) {Hello world!}; \node [style=green dot] (1) at (1.75, 5) {}; \node [style=red dot] (2) at (2.25, -0.75) {}; \node [style=none] (3) at (-3, -2) {}; \end{pgfonlayer} \begin{pgfonlayer}{edgelayer} \draw (0.center) to (1); \draw [in=30, out=45, looseness=2.25] (1) to (2); \draw (3.center) to (2); \end{pgfonlayer} \end{tikzpicture} I was able to use the label={POSITION:TEXT} option to modify the default behavior \node [style=none, label={above=Hello \textcolor{blue}{World!}}] (0) at (-2.5, 7) {}; which renders which is what I am wanting. The problem is that I do not want to manually input the position parameter for each node and I do not know how to set up a node style that will automatically position the edge connection relative to the text node without having to specify the position in each case. To put it in question form: Is there a way to set up a node style that will automatically position the connecting edge on the "outside" of the node relative to the text like the second image above? Any help is appreciated.
- 3D view of a 2D rectangleby Diaa on November 12, 2023 at 11:34 pm
I would be grateful to know how to: fix the code to make it work be able to control the viewing angle so that I can see the rectangle like the top surface of this image \documentclass{article} \usepackage{tikz-3dplot} \usetikzlibrary{perspective,calc,3d,arrows} \begin{document} \tdplotsetmaincoords{70}{110} % Set the view angles \begin{tikzpicture}[scale=2, transform shape, tdplot_main_coords] % Define the coordinates of the rectangle corners with labels \coordinate (A) at (0,0,0); \coordinate (B) at (4,0,0); \coordinate (C) at (4,1,0); \coordinate (D) at (0,1,0); % Draw the rectangle \draw (A) -- (B) -- (C) -- (D) -- cycle; % Draw x-axis \draw[->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$}; % Draw y-axis \draw[->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$}; % Draw z-axis \draw[->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$}; % Add labels to coordinates \node[above right] at (A) {$A$}; \node[above right] at (B) {$B$}; \node[above right] at (C) {$C$}; \node[above right] at (D) {$D$}; \end{tikzpicture} \end{document}
- TikZ fill behavior depends on perspective (tikz-3dplot)by Leyna Shackleton on August 11, 2023 at 10:25 pm
Here is my MWE: \documentclass{minimal} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{tikz-3dplot} \tdplotsetmaincoords{80}{-5} \begin{document} \begin{tikzpicture} \draw[fill=gray] (1.66, -2, 0) -- (1.33, -2, 0) .. controls (1.33, -0.5, -1) .. (1.33, 1, 0) -- (1.66, 1, 0) .. controls (1.66, -0.5, -1) .. (1.66, -2, 0); \end{tikzpicture} \begin{tikzpicture}[tdplot_main_coords] \draw[fill=gray] (1.66, -2, 0) -- (1.33, -2, 0) .. controls (1.33, -0.5, -1) .. (1.33, 1, 0) -- (1.66, 1, 0) .. controls (1.66, -0.5, -1) .. (1.66, -2, 0); \end{tikzpicture} \end{document} which outputs the following: I'm drawing a curved sheet for which the interior should be filled in, but precisely how this is filled in depends on the coordinate system - the first one is how it should be shaded, but it seems like if I change the perspective, TikZ gets confused and doesn't shade it in properly. Is there any way to fix this?
- Filling in capped off torus in tikz 3dby heervande on July 7, 2023 at 1:28 pm
I am trying to draw a capped off torus in tikz 3d, see MWE below. I'd like the surface to be colored in gray for the first picture, and everything below the blue line to be colored in gray for the second one. Is it possible to do this and changing as little as possible about the picture (so it will still be in the same style with some other pictures I made)? Thanks in advance \documentclass[tikz,border=1.618mm]{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} \usepackage{tikz-cd} \usepackage[]{calc} \begin{document} \tdplotsetmaincoords{80}{0} \begin{tikzpicture}[scale=5,tdplot_main_coords] \coordinate (O) at (0,0,0); \tdplotsetrotatedcoords{90}{90}{0} \tdplotdrawarc[bottom color= gray, top color= gray!40, tdplot_main_coords]{(0,-0.08,0.76604444311)}{0.64278760968}{0}{360}{}{} \tdplotdrawarc[tdplot_rotated_coords]{(O)}{1}{-140.5}{140.5}{}{} \tdplotdrawarc[tdplot_rotated_coords]{(O)}{.25}{0}{360}{}{} \end{tikzpicture} \tdplotsetmaincoords{80}{0} \begin{tikzpicture}[scale=5,tdplot_main_coords] \coordinate (O) at (0,0,0); \tdplotsetrotatedcoords{90}{90}{0} \tdplotdrawarc[tdplot_main_coords,color=blue, dashed]{(0,-0.08,0.76604444311)}{0.64278760968}{0}{180}{}{} \tdplotdrawarc[tdplot_main_coords,color=blue]{(0,-0.08,0.76604444311)}{0.64278760968}{180}{360}{}{} \tdplotdrawarc[tdplot_rotated_coords]{(O)}{1}{-140.5}{140.5}{}{} \tdplotdrawarc[tdplot_rotated_coords]{(O)}{.25}{0}{360}{}{} \tdplotsetrotatedcoords{90}{-90}{0} \tdplotdrawarc[tdplot_rotated_coords, color=blue]{(O)}{1}{-39.5}{39.5}{}{} \end{tikzpicture} \end{document}
- Trouble drawing a staircase tableby Rodrigo on October 17, 2022 at 10:50 pm
I know there are multiple posts on the forum related to staircase tables. Altought, I couldn't find one that fits my idea, mainly because the headers of each row / column are too small for what I want. My desired output is exactly the picture below, but without the vertical lines that aren't being used, i.e., to only have the saircase design (as shown in this post). Thanks for any help in advance.
- Tikz 3D plot of poles zerosby Raja Ali Riaz on September 18, 2021 at 4:43 pm
I need to make a 3D plot in tikz of the form as in the picture. It's the magnitude plot of transfer function H(s)= (s+1)(s+2)/(s+3)(s+1+j)(s+1-j) I am sorry, I have not shared any attempt because I am ignorant in tikz 3d plotting. If somebody provide the solution, it will be kick start for me and then I build up on it. Thanks in advance. My Attempt and still few things to rectify. I have plotted the graph with online help of different resources (code and picture attached). Now the problems are It is not correcting plotting the curve in y-z plane the red line and give this error message Package pgfplots Error: Sorry, you can't use 'y' in this context. PGFPlots expected to sample a line, not a mesh. Please use the [mesh] option combined with [samples y>0] and [domain y!=0:0] to indicate a twodimensional input domain. Labels are too small and not placed properly. If somebody can set view angles so it looks like the picture of the book. If somebody can help in that regard. \documentclass[border=1cm]{standalone} \usepackage{pgfplots} \usetikzlibrary{calc,math} \pgfplotsset{compat=newest} \pgfkeys{/pgf/declare function={H(\x,\y) = 3*((((((\x)^2-(\y)^2+3*(\x)+2)^2+((2*\x*\y)+3*\y)^2)+2.2204e-16)^(1/2))/(((((\x)^3+5*(\x)^2-3*\x*(\y)^2+8*x-5*(\y)^2+6)^2+(3*(\x)^2*y+10*\x*\y-(\y)^3+8*y)^2)+2.2204e-16)^(1/2)));}} \begin{document} \begin{tikzpicture} \begin{axis}[ axis lines=middle, axis on top, axis equal image, width=50cm, view={30}{10}, xmin=-4, xmax=0, ymin=-2, ymax=2, zmin=0, zmax=5, miter limit=1, xlabel=$\sigma$, xlabel style={anchor=east,xshift=-5pt,at={(xticklabel* cs:.95)}}, ylabel=$j\Omega$, zlabel=$\mathopen| H(s)\mathclose|$, zlabel style={anchor=north east}, xtick = {-3,-2,-1,0}, hide obscured x ticks=false, ytick = {-1,0,1}, ztick = {2,4}, ] \addplot3[ smooth, surf, faceted color=gray, line width=0.1pt, fill=white, domain=-4:0, y domain = -2:2, samples = 50, samples y = 50, restrict z to domain*=0:5] {H(\x,\y)}; \addplot3[domain=-2:2,samples=70, samples y = 0,red, thick] ({0},{x},{H(0,x)}); \end{axis} \end{tikzpicture} \end{document}
- Problem whit TikZ 3D graphby Magform on May 16, 2021 at 2:08 pm
I want to draw a 3D graph in tikz; something like z=x/y, this is the code that I've written: \documentclass[tikz,border=5pt]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} [ title = {Campo in funzione della forza e della carica}, xtick = {-12,-9,...,12}, ytick = {-9,-6,...,12}, xlabel = $\vec{F}$, ylabel = $q$, ticklabel style = {font = \scriptsize}, grid ] \addplot3 [surf, domain=-12:12, samples=50] { x/y }; \end{axis} \end{tikzpicture} \end{document} The problem is that where the graph shouldn't exist anyway it exists, I tried to solve the problem, maybe using asymptote instead of tikz but I still can't draw it.
- plotting a 3D coneby Nilcouv on April 21, 2020 at 2:50 pm
I'm trying to plot a cone in 3D, but I'm a little stuck. I plotted a densely dashed, then I'm trying to plot the border of the cone, divided in 3 part: The green part is static The blue part change depending on the height of the cone The red part is just a connection between a dot "h" and the blue part. I'm unable to plot the red left part of the cone, and the there is a black line when "height=0" %%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%% \documentclass[border=10pt]{standalone} %%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%% \usepackage{tikz, tkz-euclide}% permet de dessiner des figures, des graphiques \usepackage{adjustbox}% permet de déterminer une taille de fenêtre %% FONT \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{tgadventor}% paquet de police de caractère TGadventor \usepackage{sansmath}% Copie-colle la police active dans % \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES) \usepackage{xcolor} %%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%% %\input{preamble} %\input{parameters} %\input{types/f3d_fig} %%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%% \tikzset{volum3D/.style={font={\sansmath\sffamily\large}, line width=0.4mm, line cap=round, line join=round, >=latex,}} %%%%%%%%%%%%%%%%%%%%%%%% CONE %%%%%%%%%%%%%%%%%%%%%%%% \makeatletter \tikzset{pics/cone/.style={code={% \tikzset{cone/.cd,#1}% \def\pv##1{\pgfkeysvalueof{/tikz/cone/##1}}% \pgfmathsetmacro{\myan}{atan2(\pgf@zx,\pgf@xx)}% \begin{scope}[local bounding box=sph]% %%% Compute the angle \pgfmathsetmacro\angle{acos(1/\pv{height})} \path[cone/corps] %%% Patrie supérieur (0, \pv{height}*\pv{scale}, 0) coordinate (h) node[above] {\angle} node[below] {\myan} %%% Patrie droite (h) -- plot[smooth,variable=\t,samples=19,domain={(sign(\myan)*90+\myan)-\angle}:\myan] ({\pv{ray}*\pv{scale}*cos(\t)}, 0, {\pv{ray}*\pv{scale}*sin(\t)}) %%% Patrie Inférieur -- plot[smooth,variable=\t,samples=19,domain=\myan:{-1*sign(\myan)*180+\myan}] ({\pv{ray}*\pv{scale}*cos(\t)}, 0, {\pv{ray}*\pv{scale}*sin(\t)}) %%% Patrie gauche %-- plot[smooth,variable=\t,samples=19,domain={180*\myan-\myan}:\myan] %({\pv{ray}*\pv{scale}*cos(\t)}, %0, %{\pv{ray}*\pv{scale}*sin(\t)}) -- cycle ; %%% CERCLE EN POINTILLÉ \draw[thick, densely dashed] %%% Arc Avant plot[smooth,variable=\t,samples=19,domain={-1*sign(\myan)*180+\myan}:\myan] ({\pv{ray}*\pv{scale}*cos(\t)}, 0, {\pv{ray}*\pv{scale}*sin(\t)}) %%% Arc Arrière plot[smooth,variable=\t,samples=19,domain={sign(\myan)*180+\myan}:\myan] ({\pv{ray}*\pv{scale}*cos(\t)}, 0, {\pv{ray}*\pv{scale}*sin(\t)}) ; \end{scope} %% Dot (0,0) \draw (0,0,0) node[circle, fill=black, inner sep=1pt] {} coordinate (o) ; }}, cone/.cd, ray/.initial=5, height/.initial=3, scale/.initial=1, corps/.style={draw,fill=black!15}, } \makeatother %%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%% \begin{document} \begin{tikzpicture}[volum3D, x={(0:1cm)}, y={(90:1cm)}, z={(89:0.4cm), scale=0.5}] % calibration cross %\pic at (5,0,0) {calcross}; % Figures \foreach \h in {0.5,1,...,8}{ \begin{scope}[shift={(6.2*\h,0)}] \pic{cone={ray=3, height=\h, scale=0.5}}; \end{scope} } \end{tikzpicture} \end{document}
- Code highlighting drawn under tcolorbox and not displayedby Zoefschildpad on March 10, 2020 at 10:07 am
I am looking to add highlighting to listings. I have tried to adept the techniques given by https://tex.stackexchange.com/users/23765/siracusa in the question Highlight text in code listing while also keeping syntax highlighting However I have run into a problem, which is demonstrated in the example below. I want my listing to be inside a tcolorbox. When it isn't in a tcolorbox, the highlighting works as expected. When it is inside the box, the highlighting is rendered properly and in the right place, but it isn't displayed because the tcolorbox seems to be drawn on top of it. Is there a way to draw the highlighting on top of the box (but still under the text) instead? I would really like to keep the core of the highlighting solution, because it plays really nicely with the listings package. Also note that any solution that involves manually adjustments to individual codeblocks is not an option. Their contents are generated by another program, and there are thousands. \LoadClass[10pt]{book} \RequirePackage{fontspec} \RequirePackage{listings} \RequirePackage{xcolor} \RequirePackage{atbegshi} \RequirePackage{ifthen} \RequirePackage{tikz} \usetikzlibrary{calc} \usetikzlibrary{fit} \RequirePackage[breakable]{tcolorbox} % HIGHLIGHTING \makeatletter \newcommand\if@empty[1]{% \if\relax\detokenize{#1}\relax \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi } \newcommand\ifthen[2]{\ifthenelse{#1}{#2}{}} \newcommand\ifelse[2]{\ifthenelse{#1}{}{#2}} % Is highlighting currently active in the listings environment? \newif\ifhl@active % Material executed at each page shipout \newtoks\hl@shipout % Extra styling parameters for the currently active highlight \newtoks\hl@parameters % Inline highlight style. This does not break across line ends \newcommand\hl[2][]{\begingroup\hlstyle@start{#1}#2\endgroup} % The highlight style for listings environments \newcommand\hlstyle[1][]{\hlstyle@start{#1}} \newcommand\hlstyle@start[1]{% \global\hl@activetrue \aftergroup\hlstyle@end \write\@auxout{\noexpand\hl@setparameters{#1}}% \hl@mark{S}% } \newcommand\hlstyle@end{% \hl@mark{E}% \global\hl@activefalse } % Sets the current highlight parameters \newcommand\hl@setparameters[1]{% \global\hl@parameters={#1}% } % Writes a new node marker with the current position and page number to the .aux file \newcommand\hl@mark[1]{% \ensuremath{\vcenter{\hbox{\pdfsavepos}}}% \write\@auxout{\noexpand\hl@processmark{#1}{\the\pdflastxpos}{\the\pdflastypos}{\arabic{page}}}% } % Writes the current page origin to the .aux file, and issues the current \hl@shipout material % to be processed \AtBeginShipout{\AtBeginShipoutUpperLeft{% \pdfsavepos \write\@auxout{\noexpand\hl@processmark{Z}{\the\pdflastxpos}{\the\pdflastypos}{\arabic{page}}}% \hl@doshipout }} % Maintains the current first and last node positions, checks whether a node marker should be used % for the current highlighting segment, and issues a \hl@draw call if necessary. % #1 is either 'S' (start node), 'M' (intermediate node), 'E' (end node), or 'Z' (page origin) % #2/#3 are the x/y-coordinates, #4 is the page number \newcommand\hl@processmark[4]{% \if#1S% \xdef\hl@firstx{#2}% \xdef\hl@firsty{#3}% \xdef\hl@firstp{#4}% \else\if#1M% \ifthenelse{\hl@firsty=#3}{% % Still on same line \xdef\hl@lastx{#2}% \xdef\hl@lasty{#3}% }{% \ifelse{\hl@firstx=\hl@lastx \and \hl@firsty=\hl@lasty}{% % Last highlight part is not empty \expandafter\hl@draw\expandafter{\the\hl@parameters}% }% \xdef\hl@firstx{#2}% \xdef\hl@firsty{#3}% \xdef\hl@firstp{#4}% }% \else\if#1E% \ifthen{\hl@firsty=#3}{% % Still on same line \xdef\hl@lastx{#2}% \xdef\hl@lasty{#3}% \ifelse{\hl@firstx=#2}{% % Last highlight part is not empty \expandafter\hl@draw\expandafter{\the\hl@parameters}% }% }% \else\if#1Z% \xdef\hl@zerox{#2}% \xdef\hl@zeroy{#3}% \fi\fi\fi\fi } % Add a new highlight segment to \hl@shipout to be processed on every shipout. % #1 is the styling command used to draw the segment within a properly positioned \tikz call. % If #1 is empty, \hldefaultstyle is used as a default. Every styling command can take % arbitrary parameters, only the last four are mandatory (x_first, y_first, x_last, y_last) \newcommand\hl@draw[1]{% \edef\@temp{{\noexpand\tikz [ overlay, shift = {(-\hl@zerox sp, -\hl@zeroy sp)} ] {\if@empty{#1}{\noexpand\hldefaultstyle}{\unexpanded{#1}}% {\hl@firstx sp}{\hl@firsty sp}{\hl@lastx sp}{\hl@lasty sp}}}% {\hl@firstp}% }% \expandafter\global\expandafter\addto@hook\expandafter\hl@shipout\expandafter{\@temp}% } % Processes the current \hl@shipout material. The material is a sequence of % {TikZ commands}{page number} pairs \def\hl@doshipout{% \expandafter\hl@doshipout@\the\hl@shipout{}{}\@end } \def\hl@doshipout@#1#2#3\@end{% \if@empty{#2}{}{% \ifthen{\arabic{page}=#2}{#1}% \hl@doshipout@#3\@end }% } % Hook into listings' discretionary breaks \let\orig@lst@discretionary=\lst@discretionary \gdef\lst@discretionary{% \ifhl@active \hl@mark{M}% \fi \orig@lst@discretionary \ifhl@active \hl@mark{M}% \fi } % Styling command for a simple marker highlights \newcommand\hlmarkerstyle[5][yellow]{% \draw [ line width = \baselineskip, #1 ] (#2, #3) -- (#4, #5); } % Default styling command \let\hldefaultstyle=\hlmarkerstyle \makeatother \newcommand\delimstyleB{\hlstyle} %ENDHIGHLIGHTING %% Define custom verbatim as listing allowing background color and mark notation \let\verbatim\someundefinedcommand \lstnewenvironment{CustomVerbatim}[1][name=main] { \lstset{ basicstyle=\fontsize{8}{8}\ttfamily, moredelim=**[is][\delimstyleB]{`}{`}, aboveskip=3mm, breaklines=true, breakatwhitespace=false, keepspaces=true, extendedchars=true, xleftmargin=8pt, xrightmargin=8pt, framextopmargin=3pt, framexbottommargin=3pt, frame=tb, framerule=0pt, escapeinside={¬}{¬}, postbreak=\mbox{\textcolor{blue}{$\hookrightarrow$}\space}, #1 } } {} \newtcolorbox{codebox}[1][] { #1, breakable, size=fbox, arc=0mm, colback=red, colframe=red, } \begin{document} \begin{codebox}\begin{CustomVerbatim}% The text of this `codeblock should be partially highlighted. However, the red box is blocking the highlighting.` \end{CustomVerbatim}\end{codebox} \begin{CustomVerbatim}% The text of `this codeblock is properly partially highlighted, even across multiple lines because it` isn't in a tcolorbox \end{CustomVerbatim} \end{document}
- Adding coloured dashed lines inside matrix with external bracesby Milo on July 24, 2018 at 3:09 pm
This is the kind of the matrix I'm trying to create: Because I wanted labelled braces around the matrix, I've used the TikZ solution from this question. To get the dashed lines I've used the cheating dash style from this question, and drawn them taking inspiration from How to create vertical and horizontal dotted lines in a matrix?. My problem is this method requires a lot of manual adjustment. Another method to draw lines within matrices comes from How to add dash lines in Matrix, where there is a solution which uses array and arydshln. This draws them automatically, but I can't at the moment (a) change the colour, (b) add external braces to the matrix and (c) the ends of the dashed lines get cut off (this is precisely why I use cheating dash in the previous example). All these reasons suggest the TikZ method is the way to go. If only there was a better way to draw the lines automatically without having to the manually specify the start and end points? MWE \documentclass[12pt,a4paper]{article} \usepackage{mathtools} \usepackage{arydshln} % CODE BELOW FROM https://tex.stackexchange.com/a/1070/128068 % Load TikZ \usepackage{tikz} \usetikzlibrary{matrix,decorations.pathreplacing,calc} % Set various styles for the matrices and braces. It might pay off to fiddle around with the values a little bit \pgfkeys{tikz/mymatrixenv/.style={decoration=brace,every left delimiter/.style={xshift=3pt},every right delimiter/.style={xshift=-3pt}}} \pgfkeys{tikz/mymatrix/.style={matrix of math nodes,left delimiter=[,right delimiter={]},inner sep=2pt,column sep=1em,row sep=0.5em,nodes={inner sep=0pt}}} \pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}} \newcommand\mymatrixbraceoffseth{0.5em} \newcommand\mymatrixbraceoffsetv{0.2em} \newcommand*\mymatrixbraceright[4][m]{ \draw[mymatrixbrace] ($(#1.north west)!(#1-#3-1.south west)!(#1.south west)-(\mymatrixbraceoffseth,0)$) -- node[left=2pt] {#4} ($(#1.north west)!(#1-#2-1.north west)!(#1.south west)-(\mymatrixbraceoffseth,0)$); } \newcommand*\mymatrixbraceleft[4][m]{ \draw[mymatrixbrace] ($(#1.north east)!(#1-#2-1.north east)!(#1.south east)+(\mymatrixbraceoffseth,0)$) -- node[right=2pt] {#4} ($(#1.north east)!(#1-#3-1.south east)!(#1.south east)+(\mymatrixbraceoffseth,0)$); } \newcommand*\mymatrixbracetop[4][m]{ \draw[mymatrixbrace] ($(#1.north west)!(#1-1-#2.north west)!(#1.north east)+(0,\mymatrixbraceoffsetv)$) -- node[above=2pt] {#4} ($(#1.north west)!(#1-1-#3.north east)!(#1.north east)+(0,\mymatrixbraceoffsetv)$); } \newcommand*\mymatrixbracebottom[4][m]{ \draw[mymatrixbrace] ($(#1.south west)!(#1-1-#3.south east)!(#1.south east)-(0,\mymatrixbraceoffsetv)$) -- node[below=2pt] {#4} ($(#1.south west)!(#1-1-#2.south west)!(#1.south east)-(0,\mymatrixbraceoffsetv)$); } % CHEATING DASH FROM https://tex.stackexchange.com/a/133357/128068 \tikzset{ cheating dash/.code args={on #1 off #2}{ % Use csname so catcode of @ doesn't have do be changed. \csname tikz@addoption\endcsname{% \pgfgetpath\currentpath% \pgfprocessround{\currentpath}{\currentpath}% \csname pgf@decorate@parsesoftpath\endcsname{\currentpath}{\currentpath}% \pgfmathparse{\csname pgf@decorate@totalpathlength\endcsname-#1}\let\rest=\pgfmathresult% \pgfmathparse{#1+#2}\let\onoff=\pgfmathresult% \pgfmathparse{max(floor(\rest/\onoff), 1)}\let\nfullonoff=\pgfmathresult% \pgfmathparse{max((\rest-\onoff*\nfullonoff)/\nfullonoff+#2, #2)}\let\offexpand=\pgfmathresult% \pgfsetdash{{#1}{\offexpand}}{0pt}}% } } \begin{document} \begin{equation} \mathbf{X} = \begin{tikzpicture}[baseline=0cm,mymatrixenv] \matrix [mymatrix,inner sep=4pt,row sep=1em] (m) { \frac{x}{y} + C & m\omega^2 + U \\ 0 & 1 \\ 1 & \frac{x}{y} + Dx^2 \\ }; % Dashed lines \draw [cheating dash=on 2pt off 2pt,red] ([xshift=1ex,yshift=1ex]m-1-1.north east) --++(-90:2.4cm); \draw [cheating dash=on 2pt off 2pt,red] ([xshift=-0.3ex,yshift=-0.9ex]m-1-1.south west) --++(0:3.3cm); % Braces \mymatrixbraceright{1}{3}{$A$} \mymatrixbracetop{2}{2}{$B$} \end{tikzpicture} \end{equation} \begingroup \renewcommand*{\arraystretch}{1.75} \begin{equation} \mathbf{X} = \left[ \begin{array}{c;{2pt/2pt}c} \frac{x}{y} + C & m\omega^2 + U \\ \hdashline[2pt/2pt] 0 & 1 \\ 1 & \frac{x}{y} + Dx^2 \\ \end{array} \right] \end{equation} \endgroup \end{document} ADDED - I should mention that for different matrices I play around the tikz/mymatrix/.style settings, like changing inner sep and row sep. If the placement of the dashed lines could be somehow tied into those settings that would be ideal. This highlights why my current method (specifying the lengths in centimeters) is not ideal.
- Tikz pictures inside Tikz pictures: typesetting failing in lattice subgraph with edgesby hhh on April 16, 2016 at 11:29 am
I define Tikz pictures within each other. The typesetting fails in a way that the edges are not drawn properly: the edges are not drawn from the centers of vertices in the lattice subgraph structure, instead on the side of the vertices like below and the lattice subgraph structure is in 2. MWE while simplified example without the issue in 1. MWE: the issue somehow occurs only when having many tikz environments. 1. MWE draws the edges nicely between the centers of vertices \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=4pt,minimum size=3pt] \draw (0,0)node{}; \draw (1,0)node{}; \draw (0.5,1)node{}; \draw (0,0)--(1,0); \end{tikzpicture} 2. MWE not drawing the edges nicely between the centers of vertices, why? \begin{tikzpicture}[scale=1.2] \tikzstyle{every node}=[draw, circle] \node(0) { \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=0pt,minimum size=3pt] \draw (0,0)node{}; \draw (1,0)node{}; \draw (0.5,1)node{}; \end{tikzpicture} }; \node[above =of 0](1){ \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=1pt,minimum size=3pt] \draw (0,0)node{} -- (1,0)node{}; \draw (0.5,1)node{}; \end{tikzpicture} }; \node[above right =of 1](21){ \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=1pt,minimum size=3pt] \draw (0,0)node{} -- (1,0)node{} -- (0.5,1)node{}; \end{tikzpicture} }; \node[above left =of 1](22){ \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=1pt,minimum size=3pt] \draw (0,0)node{} -- (0.5,1)node{} -- (1,0)node{}; \end{tikzpicture} }; \node[above left =of 21](30){ \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=1pt,minimum size=3pt] \draw (0,0)node{} -- (1,0)node{} -- (0.5,1)node{}; \draw (0,0)node{} -- (0.5,1)node{}; \end{tikzpicture} }; \draw (0) -- (1); \draw (1) -- (21); \draw (1) -- (22); \draw (21) -- (30); \draw (22) -- (30); %\draw (21) -- (31); %\draw (21) -- (32); %\draw (21) -- (33); %\draw (31) -- (41); %\draw (31) -- (42); %\draw (32) -- (42); %\draw (33) -- (41); %\draw (22) -- (32); \end{tikzpicture} where the lattice subgraph picture has the failed typesetting, the edges not drawn between the centers. So How to draw edges properly from the centers of vertices in the lattice subgraph with many tikz environments? Perhaps relevant Nesting tikz pictures Joining different TikZ pictures What are most important variables set at the beginning of a tikzpicture? of a scope?
- Sphere Intersection using Tikzby Relative0 on November 14, 2015 at 10:42 pm
I found this example here of two intersecting spheres, have reproduced a couple Tikz spheres that I found here which is the code below. I however would like to know how to get these two spheres to intersect - but also to embed them in/draw a larger sphere around both that is just big enough in the XY plane to house the two. I am thinking more general - that somehow maybe I could just create a general "Sphere" and instantiate 3 spheres of different sizes and move them around until they look correct. That might be the good way to go. Thanks for your insights. \documentclass[tikz,border=10pt]{standalone} \usepackage{tikz-3dplot} \begin{document} \tdplotsetmaincoords{55}{5} \begin{tikzpicture} [scale=3,tdplot_main_coords,curve/.style={black}] \coordinate (O) at (0,0,0); \foreach \angle in {-90,-75,...,90} { %calculate the sine and cosine of the angle \tdplotsinandcos{\sintheta}{\costheta}{\angle}% %define a point along the z-axis through which to draw %a circle in the xy-plane \coordinate (P) at (0,0,\sintheta); %draw the circle in the main frame \tdplotdrawarc[curve]{(P)}{\costheta}{0}{360}{}{} %define the rotated coordinate frame based on the angle %\tdplotsetthetaplanecoords{\angle} %draw the circle in the rotated frame %\tdplotdrawarc[curve,tdplot_rotated_coords]{(O)}{1}{0}{360}{}{} } \end{tikzpicture} \tdplotsetmaincoords{30}{5} \begin{tikzpicture} [scale=2, tdplot_main_coords, curve/.style={black}] \coordinate (O) at (-130,0,0); \foreach \angle in {-90,-75,...,90} { %calculate the sine and cosine of the angle \tdplotsinandcos{\sintheta}{\costheta}{\angle}% %define a point along the z-axis through which to draw %a circle in the xy-plane \coordinate (P) at (0,0,\sintheta); %draw the circle in the main frame \tdplotdrawarc[curve]{(P)}{\costheta}{0}{360}{}{} %define the rotated coordinate frame based on the angle %\tdplotsetthetaplanecoords{\angle} %draw the circle in the rotated frame %\tdplotdrawarc[curve,tdplot_rotated_coords]{(O)}{1}{0}{360}{}{} } \end{tikzpicture} \end{document}
- Spiral on a truncated coneby Dinis Nunes on September 1, 2015 at 2:33 pm
I need to plot a spiral around an inverted truncated cone, starting and ending at the centre of both bases. Something like this: I've searched and found a similar solution, but for cylinders only: Helix on a cylinder I couldn't adapt it to my geometric shape in question, so any help would be appreciated. The code for the cone only: \documentclass[border=0.125cm]{standalone} \usepackage{tikz} \usetikzlibrary{3d,calc} \begin{document} \begin{tikzpicture} \draw (-1,0) arc (180:370:2cm and 1cm); \draw (-1,0) arc (180:10:2cm and 1cm); \draw (0,-3) arc (180:360:1cm and 0.5cm); \draw[dashed] (0,-3) arc (180:0:1cm and 0.5cm); \draw(0,-3) -- (-0.97,-0.18); \draw(2,-3) -- (2.97,-0.18); \shade[left color=blue!5!white,right color=blue!60!white,opacity=0.3] (-0.97,-0.18) arc (190:350:2 and 1) -- (2,-3) arc (360:180:1cm and 0.5cm) -- cycle; \shade[left color=blue!5!white,right color=blue!60!white,opacity=0.3] (1,0) ellipse (2cm and 1cm); \draw[dashed] (0.7,-3) arc (180:0:0.3cm and 0.15cm); \draw[dashed] (0.7,-3) arc (180:360:0.3cm and 0.15cm); \end{tikzpicture} \end{document} Thanks in advance, Dinis Nunes EDIT: Following Ignasi suggestion, I've added a spiral function, but my goal was making the line follow closely the wall of the cone. Code: \node[xshift=1cm,yshift=-3cm] (dummy) {}; \draw[densely dotted,scale=0.09,variable=\x,shift=(dummy)] plot[domain = 0:10*pi, samples = 400] ({\x*0.6*sin(0.3*pi*deg(\x))},{\x},{\x*0.6*cos(0.3*pi*deg(\x)});
- draw round/rectangular bracket embracing nodes in tikzby Jack Cheng on September 30, 2014 at 3:57 am
I know how to draw a curly bracket with the following code: \draw[decorate,decoration={brace,amplitude=5},-] (0.8,-0.75) -- (0.8,0.75); But now I want to draw a round bracket, or a rectangular one. Can anyone tell how can I do this? Is it possible to do this by changing "brace" to some other values? The result should look like: (some pictures) but not {some pictures}
- Improving the visual appearance of a truncated cone in TikZby Ingo on August 27, 2014 at 4:19 pm
I have drawn a truncated cone in TikZ and am generally happy with the result. Here is the output and an MWE: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[>=latex] \fill[fill=gray!50] (1,0) ellipse (0.166 and 0.5); \fill[fill=gray!50] (4,0) ellipse (0.498 and 1.5); \fill[fill=gray!50] (1, 0.5) -- (4, 1.5) -- (4, -1.5) -- (1, -0.5) -- (1, 0.5); \draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=west]{$z$}; \draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=south]{$x$}; \draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=north east]{$y$}; \draw[semithick] (1,0) ellipse (0.166 and 0.5); \draw[semithick] (4,0) ellipse (0.498 and 1.5); \draw (1, 0.5) -- (4, 1.5); \draw (1, -0.5) -- (4, -1.5); \end{tikzpicture} \end{document} However, I think that there is room for improvement. Here are some things that I could not figure out: How can we (automatically) dash the z-axis where it should be hidden, as well as part of the ellipse of one of the sides, which should not be visible? Would there be a sane way of adding some shading to the drawing, that would add depth? Can you help me out with these points?
- Rectangles around cells in tableby James on October 23, 2013 at 6:48 am
I asked a question here but, rather stupidly, added extra information after it had been answered. My additional question is this: I have a table with varying lengths of words. I want to encircle different groups of cells, including diagonals. If possible, it would be great if the rectangles don't overlap each other where possible. I looked at the answer here, which, whilst tedious, worked except for the overlap. This is where I've got to so far: \documentclass[fleqn,12pt,a4paper,landscape]{article} \usepackage{tikz} \usepackage{tabularx} \begin{document} % Introduce a new counter for counting the nodes needed for circling \newcounter{nodecount} % Command for making a new node and naming it according to the nodecount counter \newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node (\arabic{nodecount}) {#1};} % Some options common to all the nodes and paths \tikzstyle{every picture}+=[remember picture,baseline] \tikzstyle{every node}+=[inner sep=0pt,anchor=base, minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt] \tikzstyle{every path}+=[thick, rounded corners] \begin{table}[ht] \begin{minipage}[b]{1 \linewidth}\centering \begin{tabular}{cccccc} % Turn the cells needed for defining the circling paths into nodes with our custom command \tabnode{Long ago}& \tabnode{A few days ago}& \tabnode{Day before yesterday}& \tabnode{Yesterday} & & \\ & & & & \tabnode{Today} & \tabnode{Now}\\ \tabnode{Long time in the future}& \tabnode{A few days on}& \tabnode{Day after tomorrow}& \tabnode{Tomorrow} & & \\ \end{tabular} \end{minipage} \begin{tikzpicture}[overlay] % Define the circle paths \draw [blue](1.north west) -- (1.north east) -| (7.north east) |- (7.south west) |- (1.north west); \draw [red](8.south west) -| (2.north east) -| (2.south west) |- (8.south west); \draw [yellow](9.south west) -| (3.north east) -| (3.south west) |- (9.south west); \draw [green](8.south west) -| (3.north east) -| (2.south west) |- (8.south west); \end{tikzpicture} \end{table} \end{document} %%% Local Variables: %%% mode: latex %%% TeX-master: t %%% End:
- Helix on a cylinderby Grimolatto on August 24, 2013 at 8:49 am
I want to plot geodesics on a cylinder. These are straight lines, circles or helices. I can plot the first two, but I don't know how to draw the helices. To be precise, I would like to know how to draw an helix on this cylinder (passing thru two points A and B, but the location of the points is not relevant), using TikZ exclusively (maybe with pgfplots, but without using pstricks): \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \begin{document} \begin{tikzpicture} \node [cylinder,rotate=90,draw,aspect=2,minimum width=2cm,minimum height=3.5cm](C){}; \draw[fill] (-0.5,-0.5) circle [radius=0.045]node[below]{$A$}; \draw[fill] (0.5,0.75) circle [radius=0.045]node[below]{$B$}; \end{tikzpicture} \end{document}
- Manual/automatic line breaks and text alignment in TikZ nodesby Jake on July 11, 2013 at 11:04 pm
How can I insert a line break in a TikZ node? Simply putting \\ where I want the break doesn't work (see MWE). Is there a way to make lines break automatically at some specified width? And can I control the alignment of the text (left, right, centered, justified)? \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node {First line\\second line}; \end{tikzpicture} \end{document}
- 3D bodies in TikZby azetina on January 30, 2012 at 4:35 pm
Is there like a library that has default geometric figures like the ones shown below. Am not acquainted yet with 3D diagrams in TikZ.
- beamer & TikZ: gradually unveil treesby Fred on June 13, 2011 at 11:02 am
Imagine a simple tree: \begin{tikzpicture} \node {Selbstregulation} [edge from parent fork down] child {node {Kognition}} child {node {Metakognition} child {node {Planung}} child {node {Monotoring}} child {node {Regulation}} } \end{tikzpicture} Is it possible to unveil the child nodes step by step using overlays in beamer? I tried with the \onslide command at several positions around child, but it doesn't work... Any hints? - Thanks.