TikZ
- Designing consistent, good-looking inline TikZ nodes for keyboard keys and menu itemsby Marco Moldenhauer on August 29, 2026 at 6:38 pm
I am creating my own inline TikZ commands for a Blender tutorial. So far, I have defined three commands: \KeyboardLetter{...} for keyboard letters, such as \KeyboardLetter{A} \KeyboardSymbol{...} for keyboard symbols, such as \KeyboardSymbol{\shift} \BlenderMenu{...} for Blender menu items, such as \BlenderMenu{Object Mode} My main requirement is that all three types of inline nodes should have the same height, regardless of their contents. I am not particularly happy with my current design (see the output below). How could I improve the design so that keyboard letters, keyboard symbols, and Blender menu items look like they belong to the same visual system? Maybe someone has a creative idea or a nice design suggestion? 🙂 my Code \documentclass{article} \usepackage{menukeys} \tikzset{ keystroke/.style={ draw=black!50, fill=yellow!20, %drop shadow={shadow xshift=0.15ex,shadow yshift=-0.15ex,fill=black,opacity=0.7}, rectangle, %rounded corners=0.8pt, inner xsep=1.5pt, inner ysep=1.5pt, line width=0.3pt, %minimum width=0.21cm, %minimum height=0.21cm, font=\sffamily\small, %text=blue!75!black, %anchor=south } } \newcommand*\KeyboardLetter[1]{% \tikz[baseline=(key.base)] % \node[keystroke](key) {#1} ;% } \newcommand*\KeyboardSymbol[1]{% \tikz[baseline=(key.base)]{% \node[keystroke,inner sep=1.5pt] (key) {\phantom{A}}; \node[ inner sep=0.8pt, transform shape, scale=0.75 ] at (key.center) {#1}; }% } \newcommand*\BlenderMenu[1]{% \tikz[baseline=(key.base)] % \node[% keystroke, %signal, fill=red!5 ](key) {#1} ;% } \begin{document} \KeyboardSymbol{\tab}\KeyboardLetter{A}\KeyboardLetter{P}\KeyboardLetter{=}\KeyboardSymbol{\shift}\KeyboardLetter{,}\BlenderMenu{Object Mode}\BlenderMenu{Edit Mode} \end{document} my Output
- How to put tikz node at top left in a picture fitting all the A4 document?by Manuel Selva on August 29, 2026 at 8:55 am
I have the following document : \documentclass[a4paper]{article} \usepackage[a4paper,margin=0cm,landscape]{geometry} \usepackage{tikz} \usetikzlibrary{fit} \begin{document} \begin{tikzpicture}[remember picture, overlay] \coordinate (nw) at (current page.north west); \coordinate (se) at (current page.south east); \node [fill=red!10, fit=(nw) (se), inner sep=0pt] {}; \node [rectangle,fill=green,draw=black, minimum width=3cm, minimum height=3cm,anchor=north west] at (0, 0) {Manu}; \end{tikzpicture} \end{document} The Manu green rectangle is not in the top left corner of the resulting document while the red background done using fit correctly fits all the page. Why is the green rectangle shifted ?
- How make a tikzpicture filling an A4 page?by Manuel Selva on August 29, 2026 at 6:49 am
I want to use tikz to draw a diagram and I want this diagram occupy all the A4 space of my document (so that I can print it then). How can I achieve this ? Here is what I have for now : \documentclass[a4paper]{article} \usepackage{tikz} \usetikzlibrary{fit} \begin{document} \begin{tikzpicture}[remember picture, overlay] \node [fill=blue, fit=(current page.north west) (current page.south east), inner sep=0pt] {}; \end{tikzpicture} \end{document} But my problem is that I want to have a landscape A4 paper. Adding : \usepackage[a4paper,margin=0in,landscape]{geometry} results in a blue rectangle occupying only part of the document. It seems that current page.north west and current page.south east are no more valid with landscape ?
- Relative paths in pgfkeys vs. usage in TikZby karlh on August 28, 2026 at 3:12 pm
This is more a curiosity (or bug report?) than it is an actual problem. That is, I know how to fix it/work around it, and I'm really asking about the design principle(s). Using \pgfkeys to set a key /pgf/bar is fine, but setting one /pgf/foo/bar will cause an error if the \pgf part is left off inside a TikZ path/node/etc. command: \documentclass{article} \usepackage{tikz} \pgfkeys{% /pgf/bar/.initial=1cm, /pgf/foo/bar/.initial=1cm, } \begin{document} \begin{tikzpicture} \path [bar=2cm] (0,0); \end{tikzpicture} \end{document} compare to \documentclass{article} \usepackage{tikz} \pgfkeys{% /pgf/bar/.initial=1cm, /pgf/foo/bar/.initial=1cm, } \begin{document} \begin{tikzpicture} \path [foo/bar=2cm] (0,0); \end{tikzpicture} \end{document} The latter gives the following error: ! Package pgfkeys Error: I do not know the key '/tikz/foo/bar', to which you passed '2cm', and I am going to ignore it. Perhaps you misspelled it. See the pgfkeys package documentation for explanation. Type H <return> for immediate help. ... l.13 \path [foo/bar=2cm] ( 0,0); ? Making the root path /tikz solves the problem, as does providing the full path /pgf/foo/bar, but given the statement in the TikZ documentation, section 12.4.1, I expected it to work: Is this supposed to work, or is there a reason this list is not followed when a slash is present in the key name?
- tikz pgfplot fill area between multiple graphs or pathsby paul_schaefer on August 27, 2026 at 12:22 pm
MWE: \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage[ngerman]{babel} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{tikz} \usetikzlibrary{arrows.meta} \usetikzlibrary{datavisualization.formats.functions} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{fillbetween} \begin{document} \begin{tikzpicture}[scale=1] \begin{axis}[ axis equal, % axis line style=thick, axis x line=center, ylabel={$y$}, xlabel={$x$}, major tick style = {black}, axis y line=middle, every axis y label/.style={ at={(current axis.above origin)}, inner sep=3, anchor=north east, }, every axis x label/.style={ at={(current axis.right of origin)}, inner sep=3, anchor=north east, }, xtick={-1,1}, xticklabels={$-\frac{w}{2}$,$\frac{w}{2}$}, ytick={1}, yticklabels={$h$}, yticklabel style={anchor=south west}, xmin=-1.75, xmax=3.25, ymin=-0.1, ymax=1.5, height=4cm, samples=100] \addplot[domain=-1:1,thick, name path=A] {1 - x * x}; \addplot[domain=0.5:2.5,thick, name path=B] {1 - (x-1.5) * (x-1.5)}; \draw[name path=C, thin] (1/3,8/9) -- (1.5,1); \path [name path=D] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0); \addplot[black!15] fill between[of=C and A, soft clip={domain=0:0.75}]; \addplot[black!15] fill between[of=C and B, soft clip={domain=0.75:1.5}]; \addplot[black!40] fill between[of=B and D, soft clip={domain=0.5:0.75}]; \addplot[black!40] fill between[of=A and D, soft clip={domain=0.75:1}]; \end{axis} \end{tikzpicture} \end{document} results in a graph, where the areas between the both graphs are filled in gray. In this example I splitted the areas into four sections and colored them. Is there a possibility to fill the areas without splitting them into sections? A second problem is, that the separation of each area into two parts will sometimes result in in slight white vertical line between the colored areas. In my case it depends on the scaling of the pdf viewer I use. If there area could be described without separation this should not happen.
- How to draw 3D animation of reflection of a triangle about the bisector?by Learner on August 26, 2026 at 6:50 pm
I want to plot a 3D animation of an equilateral triangle about one bisector. I have plotted the steps by using tikz: \documentclass[a4paper,11pt]{article} \usepackage{tikz} \usepackage[margin=1.2cm]{geometry} \usepackage{amsmath} \begin{document} \begin{tikzpicture}[x=1cm,y=1cm] % First triangle: \begin{scope}[shift={(0,0)}] \coordinate (A) at (0,2); \coordinate (B) at (-1.732,0); \coordinate (C) at (1.732,0); % Median = axis of reflection \draw[dashed,very thick] (0,0) -- (0,2); % Triangle \draw[thick] (A) -- (B) -- (C) -- cycle; % Vertex labels \node[above] at (A) {$A$}; \node[below left] at (B) {$B$}; \node[below right] at (C) {$C$}; % Element \node at (0,-0.7) {I}; \end{scope} %Arrow from first triangle to second triangle \draw[->,thick] (2.2,1) -- (5.8,1); \node at (4,1.2) {s}; \node at (4,0.5) {$(\text{reflection})$}; %second triangle \begin{scope}[shift={(8,0)}] \coordinate (A) at (0,2); \coordinate (B) at (-1.732,0); \coordinate (C) at (1.732,0); % Reflect in the vertical median \begin{scope}[xscale=-1] % Triangle \draw[thick] (A) -- (B) -- (C) -- cycle; % Vertex labels \node[above left] at (A) {$A$}; \node[below left] at (B) {$B$}; \node[below] at (C) {$C$}; \end{scope} % Reflection axis \draw[dashed,very thick] (0,0) -- (0,2); \node at (0,-1) {II}; \end{scope} \end{tikzpicture} \end{document} which gives the following two triangles: I want to plot a 3D animation to display the reflection about the bisector.I would appreciate to do that. The vertices B and C will be changing every time but A will remain fixed. Note that the first triangle and the last triangle are same.
- tikz datavisualization place axis labels next to axis tipsby paul_schaefer on August 26, 2026 at 12:44 pm
MWE: \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[ngerman]{babel} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{tikz} \usetikzlibrary{arrows.meta} \usetikzlibrary{datavisualization.formats.functions} \begin{document} \begin{tikzpicture}[baseline=(current bounding box.center), >=Stealth]% \datavisualization[% school book axes,% visualize as smooth line,% x axis={% label={$x$},% include value={-1.25, 1.25},% ticks={% major at={% -1 as $-\frac{w}{2}$,% 1 as $\frac{w}{2}$% },% },% },% y axis={% label={$y$},% include value=1.5,% ticks={% major at={% 1 as $h$% },% node style={anchor=south west},% },% },% ]% data [format=function] {% var x : interval [-1.0:1.0];% func y = 1 - (\value x * \value x);% };% \end{tikzpicture} \end{document} provides the following graph: What do I have to change to place the axis description next to the arrow tips (shown in red)? Adding visualize label={x axis={goto pos=.5}}, to the x axis definition leads to a second label. Trying to change the node style using visualize label={node style={anchor=north}}, doesn't has any effect. How can I change/access the label inside the axis definition?
- Why \pgfkeysifdefined gives a confused result when working with \pgfkeysby lyl on August 26, 2026 at 6:50 am
\documentclass{article} \usepackage{tikz} \begin{document} \pgfkeys{/vv/.initial} \pgfkeysifdefined{/vv}{yes}{no} \end{document} Since the key vv is not given any value, why is the output "yes", not "no"?
- Why does \pgfkeysvalueof give different results between nearly same codesby lyl on August 26, 2026 at 4:34 am
\documentclass{article} \usepackage{tikz} \begin{document} \pgfkeys{my family/my key/.initial=hello} \pgfkeysvalueof{my family/my key} % Running the above two lines of code gets nothing \pgfkeys{/my family/my key/.initial=hello} \pgfkeysvalueof{/my family/my key} % Running the above two lines of code gets right output as expected. % What causes such different results between the two block of codes? \end{document}
- How to draw chemistry flowcharts [closed]by Alcino Junior on August 26, 2026 at 2:06 am
I want to know if there are some package to draw flow charts for guiding chemistry lab experiments.
- How to draw realistic scientific calculator buttons and LCD screens in LaTeX? [duplicate]by user446526 on August 25, 2026 at 8:20 am
I am currently working on a mathematical document and I need to explain how to use a scientific calculator (specifically similar to Casio models) for operations like factorials, permutations, and combinations. I would like to recreate the calculator buttons and the LCD screen natively in LaTeX so that they blend perfectly with the text, rather than inserting external images. Here is a reference image (2875.jpg) showing exactly the style I want to achieve: Specifically, I am looking to create macros for: The Buttons: Rounded shapes with a slight 3D/shadow effect. Some buttons are dark blue (like SHIFT), others are dark grey or light grey. Secondary Labels: The ability to add small text above the buttons (like the yellow x! or nCr, and the red LCM). The LCD Screen: A box that mimics the calculator screen, showing the input expression on the left, the result on the bottom right, and tiny indicators at the top (like M, D, Math). I honestly don't know how to achieve this realistic look. I suspect it requires some advanced TikZ or tcolorbox styling, but I couldn't figure out where to start. Could someone provide a minimal working example or guide me on how to design these elements elegantly? Any help would be greatly appreciated!
- How to make two TikZ nodes have exactly the same height?by Marco Moldenhauer on August 25, 2026 at 7:03 am
I am defining custom keyboard-key commands using TikZ and the menukeys package. I defined two types of keystroke commands: one containing a normal letter and another containing a symbol such as \shift. The problem is that the \keystrokeSymbol node does not have the same height as the \keystrokeLetter node. I would like the symbol key to have exactly the same height as the letter key, while still allowing the symbol to be vertically centered. What would be the most elegant TikZ/LaTeX approach to achieve this? Note: I would prefer a solution using TikZ itself, without introducing additional packages, if possible. Code \documentclass{article} \usepackage{tikz} \usepackage{menukeys} \tikzset{ keystroke/.style={ draw=black!50, fill=yellow, %drop shadow={shadow xshift=0.15ex,shadow yshift=-0.15ex,fill=black,opacity=0.7}, rectangle, %rounded corners=0.8pt, inner xsep=0.8pt, inner ysep=0.8pt, line width=0.3pt, %minimum width=0.21cm, %minimum height=0.21cm, font=\sffamily\small, text=blue!75!black, %anchor=south } } \newcommand*\keystrokeLetter[1]{% \tikz[baseline=(key.base)] % \node[keystroke,fill=green!10](key) {#1} ;% } \newcommand*\keystrokeSymbol[1]{% \tikz[baseline=(key.base)] % \node[keystroke](key) {#1} ;% } \newcommand*\menubutton[1]{% \tikz[baseline=(key.base)] % \node[% keystroke, %signal, fill=black!8 ](key) {#1} ;% } \begin{document} first press \keystrokeLetter{A} and \keystrokeSymbol{\shift}\keystrokeLetter{R}, then click on \menubutton{FILE} \menubutton{EDIT}. \end{document} Output Desired Output
- Draw circumscribed sphere and inscribed sphere of regular tetrahedronby Stephen on October 7, 2025 at 11:07 am
I need to draw circumscribed and inscribed spheres of a regular tetrahedron. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture}[x={(1mm,-3.5mm)},y={(1cm,0cm)},z={(0cm,1cm)}, contour/.style={gray,densely dashed},line width=0.8pt] % edge length \a \pgfmathsetmacro{\a}{4} \path (0,0,{sqrt(6)*\a/3}) coordinate (A) node[above] {$A$}; \path ({sqrt(3)*\a/6},-\a/2,0) coordinate (B) node[left] {$B$}; \path ({sqrt(3)*\a/6},\a/2,0) coordinate (C) node[right] {$C$}; \path ({-sqrt(3)*\a/3},0,0) coordinate (D) node[left] {$D$}; \path (0,0,0) coordinate (H) node[below] {$H$}; \path (0,0,{sqrt(6)*\a/12}) coordinate (O) node[above right] {$O$}; \fill (O) circle (1pt) (H) circle (1pt); \draw (A) -- (B) -- (C) -- cycle; \draw[dashed] (H) -- (A) -- (D) -- (B) (D) -- (C); % three contour lines \draw[contour] (A) -- ++ (0,2.2,0); \draw[contour] (H) -- ++ (0,2.2,0); \draw[contour] (O) -- ++ (0,2.2,0); % label the heights \draw[<->] ($(A)+(0,2,0)$) -- ($(O)+(0,2,0)$) node[midway,right] {$\frac{\sqrt{6}}{4}a$}; \draw[<->] ($(H)+(0,2,0)$) -- ($(O)+(0,2,0)$) node[midway,right] {$\frac{\sqrt{6}}{12}a$}; \end{tikzpicture} \end{document} If I use \shade[ball color=gray!20,opacity=0.3] (O) circle ({sqrt(6)*\a/4}); together with the shadings library, the result becomes which is abviously not that kind of sphere I want to see. Any ideas to draw?
- Draw a Möbius trip with normal vectors?by Gigi on October 21, 2024 at 3:41 pm
So, I have been trying to illustrate the fact that the Möbius band doesn't have a non-vanishing normal vector space. I was trying to replicate this kind of thing: Here is my code: \documentclass[12pt]{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepgfplotslibrary{colormaps} \usepgfplotslibrary{external} \tikzexternalize \usepackage{pgfplots} \pgfplotsset{compat=1.18} % Assure-toi que tu utilises la version appropriée \usepackage[margin=1in]{geometry} \geometry{ a4paper, left=25mm, right=25mm, top=10mm, bottom=15mm, } \usepackage{amsmath,amsthm,amssymb} \usepackage{graphicx} \newenvironment{statement}[2][Statement]{\begin{trivlist} \item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}} \begin{document} \begin{tikzpicture} \begin{axis}[ hide axis, view = {40}{40} ] \addplot3 [ surf, colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0.5)}, shader = faceted interp,opacity = 0.7, samples = 40, samples y = 4, z buffer = sort, domain = 0:360, y domain =-0.5:0.5 ] ( {(1+0.5*y*cos(x/2)))*cos(x)}, {(1+0.5*y*cos(x/2)))*sin(x)}, {0.5*y*sin(x/2) +1 } ); % Draw the orange circle \addplot3 [ samples=50, domain=-145:180, samples y=0, thick, color=orange ] ( {cos(x)}, {sin(x)}, {1} ); % Add tangent vectors that rotate as they follow the twist of the Möbius strip \addplot3 [ quiver={ u={cos(x/2)*cos(x)}, % Tangent vector with twisting effect v={cos(x/2)*sin(x)}, % Tangent vector with twisting effect w={sin(x/2)}, % Vertical component from the Möbius strip's twist scale arrows=0.2, % Adjust size of arrows }, samples=15, % Number of arrows domain=-145:180, -stealth, % Arrow style color=blue, % Color of the tangent vectors ] ( {cos(x)}, {sin(x)}, {1} ); \end{axis} \end{tikzpicture} \end{document} As you can see, it is quite far from my goal. I would like to have all the normal vectors on the orange circle juste like the Geogebra example. I don't need multiple colours and 2 directions of vectors. One colour and one direction will suffice. I hope that you I am being clear and apologise in advance if it is not the case. Thank you all in advance for your help.
- How to draw a shaded boundary using TikZby Sid on May 7, 2022 at 11:55 pm
How can I draw a simple shaded region such as the one shown below using TikZ? The shaded region bounded by the equation r1r2r3 - r1 - r2 - r3 + 2cos(theta) and is r1=r2=r3=4. The boundary will change slightly for different values of theta. For the purpose of this, we can assume theta=0. The idea here is to use TikZ with certain functions and fillbetween commands but this becomes tricky for 3D plots. This example could then be used to draw more involved boundaries Any tips/relevant posts would be helpful! EDIT I would ideally like a solution that just uses TiKZ and not pstricks.
- Setting the directionality of \tdplotdrawarc in cartesian coordinatesby Heath on March 30, 2022 at 2:54 pm
I have an issue with regards to \tdplotdrawarc in TikZ. Consider the following snippet: \documentclass{article} \usepackage{tikz,tikz-3dplot} \usetikzlibrary{intersections,fadings,decorations.pathreplacing} % interesection is not needed %\usetikzlibrary{shadows.blur} \begin{document} \tdplotsetmaincoords{70}{110} \begin{tikzpicture}[tdplot_main_coords] \draw[thick,->] (0,0,0) -- (3,0,0) node[anchor=north east]{$x$}; \draw[thick,->] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,3) node[anchor=south]{$z$}; \pgfmathsetmacro{\ax}{1} \pgfmathsetmacro{\ay}{0} \pgfmathsetmacro{\az}{1} \pgfmathsetmacro{\axx}{0} \pgfmathsetmacro{\ayy}{1} \pgfmathsetmacro{\azz}{1} \draw[->,red, thick] (0,0,0) -- (1,1,1) node[anchor=west]{$\vec{n}$}; \draw[dashed,red] (0,0,0) -- (1,0,1); \draw[dashed,red] (0,0,0) -- (1,0,0) -- (1,0,1) -- (0,0,0); \draw[dashed, black] (0,0,0) -- (1,1,0) -- (1,1,1); \draw[dashed, black] (1,1,0) -- (1,0,0); \draw[fill=red,opacity=0.1] (-3,-3,0) -- (-3,3,0) -- (3,3,0) -- (3,-3,0) -- cycle; \tdplotdrawarc[tdplot_main_coords,->]{(0,0,0)}{1}{0} {45}{anchor=east}{$\alpha$} \end{tikzpicture} \end{document} which produces: What I would like to do is something like: but I do not want to use: \tdplotgetpolarcoords{\ax}{\ay}{\az} \tdplotsetthetaplanecoords{\tdplotresphi} \tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{1}{0} {\tdplotrestheta}{anchor=east}{$\alpha$} to draw the arc, but stick to cartesian coordinates. Is this possible? And If so, how?
- Problem with 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.
- TikZ - Spherical trianglesby Averroes2 on April 1, 2021 at 7:13 am
I would like to draw this picture: The triangle ABC is a spherical one. How can I do this using TikZ?
- Plotting function ℝ² →ℝ with pole at (0,0) smoothlyby Wizard of Math on May 30, 2020 at 1:56 pm
I would like to plot the function f: ℝ² →ℝ, definited by f(x,y)=(xy)/(x^2+y^2). But the following problem comes up: At (0,0) the function is not continous and therefore it looks kind of jagged. To solve this problem i could force the function to input specific points but i can't find it anywhere an don't know if that is even possible. Code: \begin{tikzpicture}[] \begin{axis}[axis lines=center, axis on top, xtick=\empty, ytick=\empty, ztick=\empty, xrange=-2:2, yrange=-2:2 ] % function \addplot3[domain=-2:2,y domain=-2:2,colormap/viridis,surf,opacity=0.5,samples = 55] {(x*y)/(x^2+y^2)}; \end{axis} \end{tikzpicture} How do i make this function look smooth? Any help would be greatly appreciated 🙂 (Just increasing the Samples doesnt do that much, and I run into the following error: TeX capacity exceeded, sorry [main memory size=3000000])
- Tikz plotting 3dby Titanlord on May 15, 2020 at 3:05 pm
I'm trying to make a 3d plot with tikz, but I was not able to do it. I always get a rubbish messy chaos of lines heading into all directions. I wanted to plot f(x,y) = x^3 / y^2. I was able to do it with gnuplot: \begin{gnuplot} set terminal epslatex color set size 1,1 set isosamples 100 unset key set grid set xrange [-5:5] set yrange [-5:5] set zrange [-5:5] set hidden3d set view 62, 308, 1, 1 splot x**3 / y**2 lt rgb "red" \end{gnuplot} The result looks like this: This solution still has some problems. E.g. for the area around (0,0,0) there are very litte samples, so there is a lot of white space and the edges are spicky. My question: Is it even possibile to make this plot with tikz? Can the plot be smother and better looking for the area around (0,0,0)? If true, can you help me?
- pgfplot renders jagged polynomialby JohnD on November 24, 2019 at 3:21 am
I keep getting a very jagged plot of this 9th degree polynomial, regardless of using smooth or increasing the sample points. Ideas? \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{fpu} \begin{document} \begin{tikzpicture}[scale=.55] \begin{axis}[ xlabel={$x$}, ylabel={$y$} ,restrict y to domain=-10^9:10^9 ,axis lines=middle ,samples=2000, %,grid ,thick ,domain=0:4 ,xtick={0,1,2,3,4} ,ytick={0,9} ,xmin=0 ,xmax=4.5 ,ymin=-1 ,ymax=1.8 ,xlabel shift={1in} ,y tick label style={yshift={5pt}} %,legend pos=outer north east ] \addplot+[black,no marks,smooth]{1.5*x + 3.83333*x^2 - 15.0104*x^3 + 22.7454*x^4 - 19.2028*x^5 + 9.37731*x^6 - 2.5978*x^7 + 0.377315*x^8 - 0.0222801*x^9}; \end{axis} \end{tikzpicture} \end{document}
- tikz-3dplot: Find projection of a vector on a unitary sphereby UJIN on January 15, 2016 at 2:07 pm
I am using TikZ (with the 3dplot package) to draw figures that mostly represent vectors lying on 2-Spheres surfaces. I have to say I am a bit of a newbie with TikZ, but I think i got the basic concepts. In this MWE I am drawing a figure with 3 unitary length vectors m, n and l (with m orthogonal to both l and n). I also have a point x that lies on the "meridian" connecting m and l, and its orthogonal projection xp on the n,m plane. \documentclass{article} \usepackage{tikz} \usepackage{tikz-3dplot} \begin{document} \begin{figure}[ht] \centering \tdplotsetmaincoords{70}{135} \pgfmathsetmacro{\rvec}{1} \pgfmathsetmacro{\thetavec}{320} \pgfmathsetmacro{\phivec}{240} \begin{tikzpicture}[tdplot_main_coords, scale=8] \coordinate (O) at (0,0,0); \draw[thick,->] (O) -- (0,\rvec,0) node[anchor=north west]{$\mathbf{n}$}; \draw[thick,->] (O) -- (0,0,\rvec) node[anchor=south]{$\mathbf{m}$}; \tdplotsetcoord{X}{\rvec}{\thetavec}{\phivec}; \tdplotsetcoord{L}{\rvec}{270}{\phivec} \draw[thick,->] (O) -- (X) node[anchor=east]{$\mathbf{x}$}; \draw[thick,->] (O) -- (L) node[anchor=east]{$\mathbf{l}$}; \draw[thick,->] (O) -- (Xyz) node[anchor=south east]{$\mathbf{x_p}$}; \draw[dashed] (X) -- (Xyz); \tdplotsetthetaplanecoords{90}; \tdplotdrawarc[tdplot_rotated_coords, style=dashed]{(O)}{\rvec}{0}{90}{}{}; \tdplotsetthetaplanecoords{\phivec}; \tdplotdrawarc[tdplot_rotated_coords, style=dashed]{(O)}{\rvec}{-90}{0}{}{}; \end{tikzpicture} \end{figure} \end{document} My question is: Is it possible to draw a line that connects xp to its projection on the sphere? Or, alternatively, a line that starts from the origin and stops at the projection of xp on the sphere? In another context I would have simply L2-normalized xp to unitary lenght, but in TikZ this doesn't seem to be a viable option (correct me if I'm wrong). For a better understanding, the picture shows what I am looking for: that really ugly red segment. Thank you for your time and sorry for the occasionally bad English!
- TiKz. Angle between two vectors and a projectionby JUAN G R on September 12, 2015 at 9:16 am
I'm having trouble to draw something with TiKz. What I want to draw I think is simple: SIM is a vector in the YZ-plane with a Beta = 38Âş, source is just a random vector with positive x and y components and negative z. Theta is the angle between SIM and source vectors and Phi is the angle formed by the source projection in the XZ-plane with the X-axis. Thanks a lot in advance
- Special decoration for TikZ pin featureby Chris on June 15, 2014 at 9:37 am
I try to achieve the curvy pin style I sketched below. It would help to distinguish pin lines from grid and other lines in the diagram. How can I realize a decoration that automatically draws such a curve? How can I integrate this with the pin feature? The code for the picture: \documentclass[tikz,convert]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture}[ pin distance=5mm, every pin edge/.style={ decorate, decoration={ snake, pre length=4pt } } ] \begin{axis}[ width=12cm, height=5cm, xmin=0,xmax=4, ] \addplot coordinates {(1,1) (3,3)} coordinate [pos=.5] (a) coordinate [pos=.7] (b); \node [pin=135:From the manual] at (a) {}; \path (a) ++(-45:1cm) node (c) {What I want}; \draw [gray] (c) to[out=110,in=-70] (a); \path (b) ++(-45:.8cm) node [right] (d) {What I want II}; \draw [gray] (d.west) to[out=160,in=-20] (b); \end{axis} \end{tikzpicture} \end{document} (I tagged with pgfplots as well since this would be a common application.)
- Drawing intersecting 3D surface plotsby eiterorm on May 11, 2014 at 11:21 am
I'm attempting to draw six semi-transparent intersecting spheres of different colors---two on each axis x, y, z and all joining at the origin---as shown in the figure below. Note how all the spheres intersect. Seeing as this figure is created in Matlab, I tried converting the figure to pgfplots code, using matlab2tikz, but this did not work. Below is the Matlab code for the figure. Theta=linspace(0,2*pi,200); Phi=linspace(-pi/2,pi/2,200); [theta,phi]=meshgrid(Theta,Phi); rho1=cos(theta).*cos(phi); rho2=-cos(theta).*cos(phi); rho3=sin(theta).*cos(phi); rho4=-sin(theta).*cos(phi); rho5=sin(phi); rho6=-sin(phi); [x1,y1,z1]=sph2cart(theta,phi,rho1); [x2,y2,z2]=sph2cart(theta,phi,rho2); [x3,y3,z3]=sph2cart(theta,phi,rho3); [x4,y4,z4]=sph2cart(theta,phi,rho4); [x5,y5,z5]=sph2cart(theta,phi,rho5); [x6,y6,z6]=sph2cart(theta,phi,rho6); surf(x1,y1,z1,'FaceColor','red','EdgeColor','none') hold on surf(x2,y2,z2,'FaceColor','red','EdgeColor','none') surf(x3,y3,z3,'FaceColor','blue','EdgeColor','none') surf(x4,y4,z4,'FaceColor','blue','EdgeColor','none') surf(x5,y5,z5,'FaceColor','green','EdgeColor','none') surf(x6,y6,z6,'FaceColor','green','EdgeColor','none') alpha(0.6) camlight left lighting flat Next I tried drawing the figure in tikz-3dplot and pst-solides3d. With both of these methods, I had the problem that the surfaces didn't intersect. Instead, 2-dimensional projections of the spheres were drawn separately on the canvas, one on top of the other, as shown in the figures below. The first figure is the output from tikz-3dplot, and the second figure is the output from pst-solides3d. With tikz-3dplot, I also had an issue with certain axes appearing to be on top of the spheres, when they should rather appear to be inside them (ref. the negative half of the y axis). Below are the codes for the above figures, in the same order. \documentclass[11pt]{standalone} \usepackage[utf8]{inputenc} \usepackage{tikz,tikz-3dplot} \usetikzlibrary{arrows} \begin{document} \tdplotsetmaincoords{70}{135} \begin{tikzpicture}[tdplot_main_coords,fill opacity=.5,>=latex] \pgfsetlinewidth{.1pt} \tdplotsphericalsurfaceplot{72}{36}{4*abs(cos(\tdplotphi)*sin(\tdplottheta))}{black!85!white}{blue} {\draw[color=black,thick,->] (-6,0,0) -- (6,0,0) node[anchor=north east]{\textbf{x}};} {\draw[color=black,thick,->] (0,-6,0) -- (0,6,0) node[anchor=north west]{\textbf{y}};} {\draw[color=black,thick,->] (0,0,-6) -- (0,0,6) node[anchor=south]{\textbf{z}};} \tdplotsphericalsurfaceplot{72}{36}{4*abs(cos(\tdplottheta))}{black!85!white}{green} {\draw[color=black,ultra thin,->] (-6,0,0) -- (6,0,0) node[anchor=north east]{};} {\draw[color=black,ultra thin,->] (0,-6,0) -- (0,6,0) node[anchor=north west]{};} {\draw[color=black,ultra thin,->] (0,0,-6) -- (0,0,6) node[anchor=south]{};} \tdplotsphericalsurfaceplot{72}{36}{4*abs(sin(\tdplotphi)*sin(\tdplottheta))}{black!85!white}{red} {\draw[color=black,ultra thin,->] (-6,0,0) -- (6,0,0) node[anchor=north east]{};} {\draw[color=black,ultra thin,->] (0,-6,0) -- (0,6,0) node[anchor=north west]{};} {\draw[color=black,ultra thin,->] (0,0,-6) -- (0,0,6) node[anchor=south]{};} \end{tikzpicture} \end{document} \documentclass[11pt]{standalone} \usepackage[utf8]{inputenc} \usepackage{pstricks,pst-solides3d} \begin{document} \begin{pspicture}(-6,-6)(6,6) \psset{viewpoint=100 100 100,Decran=150} \axesIIID[showOrigin=true,mathLabel=false,axisemph=\textbf,labelsep=8pt](-7,-7,-7)(7,7,7) \psSolid[object=sphere,r=2,action=draw*,fillcolor=green,linecolor=black!85!white,linewidth=0.5pt,opacity=0.6,ngrid=15 24,name=green2](0,0,-2) \psSolid[object=sphere,r=2,action=draw*,fillcolor=blue,linecolor=black!85!white,linewidth=0.5pt,opacity=0.6,ngrid=15 24,name=blue2](-2,0,0) \psSolid[object=sphere,r=2,action=draw*,fillcolor=red,linecolor=black!85!white,linewidth=0.5pt,opacity=0.6,ngrid=15 24,name=red2](0,-2,0) \psSolid[object=sphere,r=2,action=draw*,fillcolor=green,linecolor=black!85!white,linewidth=0.5pt,opacity=0.6,ngrid=15 24,name=green1](0,0,2) \psSolid[object=sphere,r=2,action=draw*,fillcolor=red,linecolor=black!85!white,linewidth=0.5pt,opacity=0.6,ngrid=15 24,name=red1](0,2,0) \psSolid[object=sphere,r=2,action=draw*,fillcolor=blue,linecolor=black!85!white,linewidth=0.5pt,opacity=0.6,ngrid=15 24,name=blue1](2,0,0) \end{pspicture} \end{document} How can I obtain the intended result and make the spheres actually intersect as shown in the first figure? Is there anything I can add to my methods above to make the spheres intersect? If not, are there other methods I can use to obtain the intended result? The output must be vector graphics and use the same font as the main document.
- How can I draw a 3D, three-sided 5-7-9 triangle with TikZ or PSTricks?by minthao_2011 on March 29, 2014 at 11:23 pm
I want to draw a triangle with three sides 5, 7, 9 and its incircle in geometry 3D. I used GeospacW. I tried Draw a circle (T) has center origin and has radius r=15/sqrt(11). Take a point A on (T) and draw a circle (C1) has center A and has radius r=5. Find the intersection of points between (T) and (C1), say one of them is B. Draw a circle (C2) has center B and has radius 7. Find the intersection of points between (T) and (C2), say one of them is C. Draw the triangle ABC and its incircle. After drawing the triangle, I draw a pyramid DABC with DC perpendicular to the plane (ABC) and DC=\sqrt{33}/2.
- 2D and 3D vectors in Tikzby alexT on March 7, 2014 at 5:08 am
I would like to draw some 2D and 3D vectors in Tikz with certain properties. The following primitive graph sums what I desire: I just need the first quadrant of the Cartesian coordinate system for my representation. I need the vector to be connected to the respective values on the distinct dimensions(not a projection, just orthogonal dashed lines). The code segment below does what I want to achieve in 3D with two exceptions: The projections on the xy plane and z dimension are given instead of connecting the head of the vector to the corresponding value in each dimension. Numerical values are missing in dimensions. Code: \documentclass[tikz]{standalone} \usepackage{tikz-3dplot} \begin{document} \tdplotsetmaincoords{60}{120} \begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,blue,thick}, vector/.style={-stealth,red,very thick}, vector guide/.style={dashed,red,thick}] %standard tikz coordinate definition using x, y, z coords \coordinate (O) at (0,0,0); %tikz-3dplot coordinate definition using r, theta, phi coords \tdplotsetcoord{P}{.8}{55}{60} %draw axes \draw[axis] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$}; \draw[axis] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$}; \draw[axis] (0,0,0) -- (0,0,1) node[anchor=south]{$z$}; %draw a vector from O to P \draw[vector] (O) -- (P); %draw guide lines to components \draw[vector guide] (O) -- (Pxy); \draw[vector guide] (Pxy) -- (P); \end{tikzpicture} \end{document}
- Moebius Strip using TikZby Dox on June 10, 2013 at 11:19 pm
I'm wondering whether is possible to draw a Moebius Strip using TikZ. The closest thing I've seen is in Texamples' page, but no luck so far! Do you have any ideas? I don't even have a MWE (sorry)
- Creating a staircase shaped tableauby utdiscant on September 16, 2012 at 11:37 pm
I want to create a tableau of vectors in LaTeX, like the one seen on Slide 7 in these slides. But unlike in the slides, I want to have vectors like the one given by the code below \begin{pmatrix} 1\\ 0\\ -1 \end{pmatrix} placed inside the cells. Is there an elegant way to do this, using either TikZ or tables?
- Perspective transformby mabartibin on April 19, 2012 at 2:10 pm
The following piece of eye candy: was produced using the following code: \documentclass[a4paper]{article} \usepackage{tikz} \usetikzlibrary{shapes.arrows} \usetikzlibrary{shadows.blur} \makeatletter \def\sin@alpha{0.9} \def\cos@alpha{0.006} % scaled with eye distance... never mind. \def\kappa{0.551784} % control point inset for almost-circles \def\pgf@pos@transform#1#2{% \ifpgf@pt@identity% \else% \pgf@pt@temp=#1% #1=\pgf@pt@aa#1% \advance#1 by\pgf@pt@ba#2% #2=\pgf@pt@bb#2% \advance#2 by\pgf@pt@ab\pgf@pt@temp% \fi% \advance#1 by\pgf@pt@x% \advance#2 by\pgf@pt@y% \pgfmathsetmacro{\denominator}{1+\cos@alpha*#2)}% \pgfmathparse{#1/\denominator}% #1=\pgfmathresult pt% #2=\sin@alpha#2% \pgfmathparse{#2/\denominator}% #2=\pgfmathresult pt% } \makeatother \begin{document} \begin{center} \begin{tikzpicture}[yshift=5cm] \draw[help lines] (-5,-5) grid (5,5); \def\r{5} \draw[thick,draw opacity=0.3,ball color=blue!20,blur shadow] (\r,0) .. controls(\r,\kappa*\r) and (\kappa*\r,\r) .. (0,\r) .. controls(-\kappa*\r,\r) and (-\r,\kappa*\r) .. (-\r,0) .. controls(-\r,-\kappa*\r) and (-\kappa*\r,-\r) .. (0,-\r) .. controls(\kappa*\r,-\r) and (\r,-\kappa*\r) .. (\r,0) -- cycle; \foreach \r in {1,2,3,4} { \draw[draw opacity=0.3] (\r,0) .. controls(\r,\kappa*\r) and (\kappa*\r,\r) .. (0,\r) .. controls(-\kappa*\r,\r) and (-\r,\kappa*\r) .. (-\r,0) .. controls(-\r,-\kappa*\r) and (-\kappa*\r,-\r) .. (0,-\r) .. controls(\kappa*\r,-\r) and (\r,-\kappa*\r) .. (\r,0) -- cycle; } \node[arrow box,rotate=45,arrow box arrows={north:6cm,east:6cm,south:6cm,west:6cm}, draw,top color=blue!20, arrow box shaft width=5mm,arrow box head extend=2mm,arrow box head indent=1mm, minimum width=5mm,minimum height=5mm,blur shadow] at (0,0) {}; \end{tikzpicture} \end{center} \end{document} (for the blurred shadows, you have to get the pgf-blur package from CTAN. Otherwise just change blur shadow to drop shadow) The code for the grid, ellipses, and arrows is completely independent of the perspective transform. That is handled by doing nasty things to the low level \pgf@pos@transform macro. So far so good. But... The circle has to be emulated using Bézier splines because the coordinate transform is done before circles are transformed to splines. the same will be true for any ellipses, arcs, rounded corners, etc. in this case transforming the control points gives a close enough approximation to the transformed Bézier spline, but that's just luck. In general, any curve-to might have to be decomposed into several pieces to get better approximations. setting up the perspective transform is really low level. Any suggestions about how to do this properly? Maybe with a decoration?