• How to reproduce the correct intersection curve of two 3D surfaces using PGFPlots?
    by Samia Rani on August 10, 2026 at 10:50 am

    I am trying to reproduce a 3D figure from a mathematics book in LaTeX using TikZ/PGFPlots. The figure shows two surfaces and their intersection. The two surfaces are given by x^2 + xy - y - 3z = 0 and 2x^2 + 3xy - 2y - 3z = 0. I plotted both surfaces directly from their equations and also added their intersection curve. However, the shape and especially the intersection curve in my output look quite different from the figure in the book, even though I am using the same equations. I am not sure whether the difference is caused by the viewing angle, the plotting ranges, the parametrization of the intersection curve, or something else. Here is my current code: \documentclass[border=5pt]{standalone} \usepackage{pgfplots} \usepackage{tikz} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ view={120}{25}, axis lines=none, xmin=-2.5, xmax=2.5, ymin=-2.5, ymax=2.5, zmin=-5, zmax=5, width=11cm, height=8cm, ticks=none, ] %================================================ % GREEN SURFACE % 2x^2 + 3xy - 2y - 3z = 0 %================================================ \addplot3[ surf, shader=interp, colormap={greenmap}{ color(0cm)=(green!15); color(1cm)=(green!35) }, colormap name=greenmap, domain=-2:2, y domain=-2:2, samples=35, samples y=35, opacity=0.65, ] { (2*x^2 + 3*x*y - 2*y)/3 }; %================================================ % BLUE SURFACE % x^2 + xy - y - 3z = 0 %================================================ \addplot3[ surf, shader=interp, colormap={bluemap}{ color(0cm)=(blue!15); color(1cm)=(blue!35) }, colormap name=bluemap, domain=-2.2:2.2, y domain=-2.2:2.2, samples=30, samples y=30, opacity=0.55, ] { (x^2 + x*y - y)/3 }; %================================================ % INTERSECTION CURVE % gamma(t) = % ( t, -t^2/(2t-1), t^3/(3(2t-1)) ) %================================================ \addplot3[ very thick, red, samples=100, domain=-2.2:0.35, variable=\t, ] ( {\t}, {-\t^2/(2*\t-1)}, {\t^3/(3*(2*\t-1))} ); \addplot3[ very thick, red, samples=50, domain=0.65:2.2, variable=\t, ] ( {\t}, {-\t^2/(2*\t-1)}, {\t^3/(3*(2*\t-1))} ); \end{axis} \end{tikzpicture} \end{document} The book's figure has a noticeably different orientation and shape for the two surfaces and their intersection. The book's figure looks like this: My current output looks like this: Could someone please explain what is causing this difference and how I can modify my PGFPlots code to obtain a figure that looks like the one in the book? In particular, I would like to know whether I should change the view angles, the plotting domains, or the parametrization of the intersection curve.

  • How can I draw the plane and intersection curve on a one-sheet hyperboloid in TikZ?
    by Samia Rani on August 9, 2026 at 5:23 pm

    I am trying to recreate the following mathematical figure in LaTeX/TikZ. The figure shows the one-sheet hyperboloid x^2 + y^2 - z^2 = 1 together with the plane 2x + z = 1. Their intersection is the red curve shown on the hyperboloid. After quite a lot of effort, I have managed to draw the one-sheet hyperboloid reasonably well in TikZ. However, I am having difficulty with the two remaining parts: How can I draw the transparent red plane 2x + z = 1 behind/in front of the hyperboloid, as shown in the reference image? How can I draw the red intersection curve between the plane and the hyperboloid so that it lies correctly on the surface? I would like the final figure to look as close as possible to the reference image, including the perspective, transparency of the plane, and the red intersection curve. Here is the code I currently have for the hyperboloid: \documentclass[border=5pt]{standalone} \usepackage{pgfplots} \usepackage{tikz} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture}[>=stealth] \begin{axis}[ view={120}{22}, axis lines=none, xmin=-3.3, xmax=3.3, ymin=-3.3, ymax=3.3, zmin=-2.0, zmax=2.0, xtick=\empty, ytick=\empty, ztick=\empty, clip=false, ] %------------------------------------------------ % Red point at the origin %------------------------------------------------ \addplot3[ only marks, mark=*, mark size=2.5pt, draw=red, fill=red, ] coordinates {(0,0,0)}; %------------------------------------------------ % Smooth one-sheet hyperboloid %------------------------------------------------ \addplot3[ surf, shader=interp, draw=blue!55!black, opacity=0.65, samples=45, samples y=80, domain=-2.2:2.2, y domain=0:360, z buffer=sort, ] ( {sqrt(1+x^2)*cos(y)}, {sqrt(1+x^2)*sin(y)}, {x} ); %------------------------------------------------ % POSITIVE x-axis %------------------------------------------------ \draw[ ->, black, thick ] (axis cs:0,0,0) -- (axis cs:5.0,0,0) node[right] {$x$}; %------------------------------------------------ % NEGATIVE x-axis -- dashed %------------------------------------------------ \draw[ dashed, black, thick ] (axis cs:0,0,0) -- (axis cs:-2.0,0,0); %------------------------------------------------ % POSITIVE y-axis %------------------------------------------------ \draw[ ->, black, thick ] (axis cs:0,0,0) -- (axis cs:0,4.0,0) node[above left] {$y$}; %------------------------------------------------ % NEGATIVE y-axis -- dashed %------------------------------------------------ \draw[ dashed, black, thick ] (axis cs:0,0,0) -- (axis cs:0,-1.0,0); %------------------------------------------------ % POSITIVE z-axis %------------------------------------------------ \draw[ ->, black, thick ] (axis cs:0,0,0) -- (axis cs:0,0,3.0) node[above] {$z$}; %------------------------------------------------ % NEGATIVE z-axis -- dashed %------------------------------------------------ \draw[ dashed, black, thick ] (axis cs:0,0,0) -- (axis cs:0,0,-2.0); %------------------------------------------------ % Origin %------------------------------------------------ \node[ below right, inner sep=1pt ] at (axis cs:0,0,0) {$0$}; %------------------------------------------------ % Equation %------------------------------------------------ \node[ blue!75!black, font=\large ] at (axis cs:2.0,-0.5,1.1) {$x^2+y^2-z^2=1$}; \end{axis} \end{tikzpicture} \end{document} I would be very grateful for any suggestions on how to add the plane and, especially, the intersection curve correctly. Thank you!

  • align hitbox of rotated reference cited in TikZ image
    by ali bab613 on August 8, 2026 at 2:52 pm

    I have a document which calls a .tex file that contains a standalone TikZ image. Within that image, I cite several references in a rotated node. I have the MWE here: main.tex: \documentclass{article} \usepackage{tikz} \usepackage{standalone} \usepackage{hyperref} \begin{document} \input{Chapter1} \bibliographystyle{IEEEtran} \bibliography{references} \end{document} and Chapter 1.tex: \documentclass{standalone} \usepackage{hyperref} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node[color=black,rotate=17] at (3.25,-2.35) {\tiny\cite{Test1,Test2,Test3,Test4,Test5}}; \end{tikzpicture} \end{document} Most answers online deal with hyperref to an image that's entirely rotated, in my case this is one node amongst many, and the picture is not rotated. I did not suppress the hitboxes in hyperref (by using \usepackage[breaklinks]{hyperref}) for demonstration purposes, but the problem (obviously) persists for both cases. Here's a screenshot of the resulting image, and its hitboxes: The issue is not only that the box does not rotate (which isn't a massive problem), it's more that it does not align vertically, especially the further along the node you go. Changing the citation to {\tiny\cite{Test1,Test2,Test3,Test4}\cite{Test5}} also does not adjust the box vertically: This may be a long shot, but is there a way to better align the hitbox with the node?

  • TikZ to draw an arrow along the side of a table
    by Maronite Monks on August 7, 2026 at 2:06 pm

    I have a table to which I'd like to add a curved arrow (with an arrowhead at one end) running outside the table. The line will originate at the upper left portion of a table and end with the arrow pointing at the lower left portion. Another similar arrow will be outside the lower right side of the table and end pointing at the upper right side. I'd like some text to follow the curve of the arrows on each side of the table. The text for the left arrow will say: "Gives rise to the irascible". The text on the right will say: "Resolves in the concupiscible". Here's a MWE I've compiled with LuaLaTeX. \documentclass[12pt]{memoir} \addtolength\tabcolsep{.5in} \renewcommand\arraystretch{1.5} \begin{document} \begin{center} \begin{tabular}{c|c} \hline\hline {\scshape Good}& {\scshape Evil}\\\hline\hline\\[-9pt] love & hate \\\hline desire & avoid \\\hline joy & sad \\\hline\hline\\[-9pt] hope & bold \\\hline despair & fear \\\hline\hline\\[-9pt] & anger \end{tabular} \end{center} \end{document}

  • How to easily draw and parameterize various pH titration curves (including diprotic/dibasic) for a beginner?
    by user446526 on August 6, 2026 at 8:23 am

    I am a complete beginner when it comes to drawing complex functional plots in LaTeX. I am trying to create several types of pH titration curves for a document, but I am struggling to write the code from scratch. I found a very helpful French website that seems to have the exact mathematical logic and LaTeX code for what I need: https://www.astrolabe-science.fr/courbes-titrages-acido-basiques-latex/ However, as a beginner, I find it quite difficult to extract just the essential parts to create a simple, easily editable template. I need to recreate the following types of curves (I have attached images of what I am aiming for): The 4 basic monoprotic titrations: Strong Acid, Strong Base, Weak Acid, and Weak Base. Diprotic acid titration: A curve with two equivalence points (increasing pH). Dibase titration: A curve with two equivalence points (decreasing pH). My request: Could someone help provide a simplified, beginner-friendly pgfplots (or TikZ) template based on the math from that website? Ideally, I am looking for a code structure where the main parameters (like initial concentrations, volumes, and pK_a values) are defined at the top so I can easily change them. It would be incredibly helpful if you could include brief comments/instructions inside the code explaining how to switch between the different types of curves (e.g., "change this sign for a base", "uncomment this for a diprotic acid"). Thank you so much for your time and help! I have attached images of what I am aiming for.

  • Code Review: A custom TikZ package for drawing Chemistry Reaction Progress Tables (ICE tables)
    by Natsu on August 3, 2026 at 2:33 pm

    As part of my workflow for typesetting educational materials, I frequently need to draw Chemistry Reaction Progress Tables (often known as ICE tables). To automate this, I am developing a small custom package using tikz called tkzPhysTab. The package calculates the grid coordinates automatically based on the number of reactants and products, places the $+$ and $\rightarrow$ signs, and allows adding rows dynamically. Here is the package code (tkzPhysTab.sty): \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{tkzPhysTab}[2025/11/07 Physical Reaction Table by Khaldi] \RequirePackage{tikz} % ============================= % Default Values % ============================= \def\tkzPhysTabFirstColWidth{1.5} % Width of the first column \def\tkzPhysTabColWidth{2.5} % Width of the data columns \def\tkzPhysTabRowHeight{1.0} % Row height % ============================= % Setup pgfkeys % ============================= \pgfkeys{ /tkzPhysTab/.is family, /tkzPhysTab, firstcol/.store in = \tkzPhysTabFirstColWidth, colwidth/.store in = \tkzPhysTabColWidth, rowheight/.store in = \tkzPhysTabRowHeight, reset/.code = { \def\tkzPhysTabFirstColWidth{1.5} \def\tkzPhysTabColWidth{2.5} \def\tkzPhysTabRowHeight{1.0} } } % Counters (Note: I am aware calling \newcounter here might cause issues if called twice, looking for better alternatives) \newcounter{tkzcolsOne} \newcounter{tkzcolsTwo} \newcounter{tkzlevel} \newcounter{tkzrows} % ============================= % Table Initialization Command % ============================= \newcommand{\tkzPhysicsTabInit}[4][]{% % Reset default values \pgfkeys{/tkzPhysTab/reset} % Apply custom options from [options] \pgfkeys{/tkzPhysTab,#1} \setcounter{tkzcolsOne}{0} \setcounter{tkzcolsTwo}{0} \setcounter{tkzlevel}{1} \setcounter{tkzrows}{0} \foreach \c in {#3}{\stepcounter{tkzcolsOne}} \foreach \c in {#4}{\stepcounter{tkzcolsTwo}} \foreach \r in {#2}{\stepcounter{tkzrows}} \pgfmathtruncatemacro{\ncolData}{\thetkzcolsOne + \thetkzcolsTwo} \pgfmathtruncatemacro{\nrows}{\thetkzrows + 1} \pgfmathsetmacro{\W}{\tkzPhysTabFirstColWidth + \ncolData * \tkzPhysTabColWidth} \pgfmathsetmacro{\H}{\nrows * \tkzPhysTabRowHeight} \coordinate (T) at (0,0); \draw[very thick] (T) rectangle (\W,-\H); % Vertical lines \draw (\tkzPhysTabFirstColWidth, 0) -- (\tkzPhysTabFirstColWidth, -\H); \foreach \i in {1,...,\ncolData}{ \pgfmathsetmacro{\xpos}{\tkzPhysTabFirstColWidth + \i * \tkzPhysTabColWidth} \draw (\xpos, -\tkzPhysTabRowHeight) -- (\xpos, -\H); } % Horizontal lines \foreach \j in {1,...,\nrows}{ \draw (0, -\j*\tkzPhysTabRowHeight) -- (\W, -\j*\tkzPhysTabRowHeight); } % Reactants \foreach [count=\i from 1] \c in {#3} { \pgfmathsetmacro{\xcenter}{\tkzPhysTabFirstColWidth + (\i - 0.5) * \tkzPhysTabColWidth} \node at (\xcenter, -\tkzPhysTabRowHeight/2) {\c}; \ifnum\i>1 \pgfmathsetmacro{\xplus}{\tkzPhysTabFirstColWidth + (\i - 1) * \tkzPhysTabColWidth} \node at (\xplus, -\tkzPhysTabRowHeight/2) {$+$}; \fi } % Arrow between reactants and products \pgfmathtruncatemacro{\nReact}{\thetkzcolsOne} \pgfmathsetmacro{\xarrow}{\tkzPhysTabFirstColWidth + \nReact * \tkzPhysTabColWidth} \node at (\xarrow, -\tkzPhysTabRowHeight/2) {$\rightarrow$}; % Products \foreach [count=\i from 1] \c in {#4} { \pgfmathsetmacro{\xcenter}{\xarrow + (\i - 0.5) * \tkzPhysTabColWidth} \node at (\xcenter, -\tkzPhysTabRowHeight/2) {\c}; \ifnum\i>1 \pgfmathsetmacro{\xplus}{\xarrow + (\i - 1) * \tkzPhysTabColWidth} \node at (\xplus, -\tkzPhysTabRowHeight/2) {$+$}; \fi } % Row labels \foreach [count=\j from 1] \r in {#2} { \pgfmathsetmacro{\ycenter}{-(\j + 0.5) * \tkzPhysTabRowHeight} \node at (\tkzPhysTabFirstColWidth/2, \ycenter) {\r}; } } % ============================= % Add Row Command % ============================= \newcommand{\tkzPhysicsTabLine}[1]{% \stepcounter{tkzlevel} \foreach [count=\i from 1] \val in {#1} { \pgfmathsetmacro{\xcenter}{\tkzPhysTabFirstColWidth + (\i - 0.5) * \tkzPhysTabColWidth} \pgfmathsetmacro{\ycenter}{-(\thetkzlevel - 0.5) * \tkzPhysTabRowHeight} \node at (\xcenter, \ycenter) {\val}; } } And here is the Minimum Working Example (MWE) generating the table: \documentclass[border=5mm]{standalone} \usepackage{tkzPhysTab} \begin{document} \begin{tikzpicture} \tkzPhysicsTabInit[firstcol=2.0,colwidth=3,rowheight=1.2]% {$x=0$,$x=t$,$x=f$}% {$Fe_3O_4$,$4H_2$}% {$3Fe$,$4H_2O$} \tkzPhysicsTabLine{$2.18$,$9.65$,$0$,$0$} \tkzPhysicsTabLine{$2.18-x$,$-4x$,$?$,$?$} \tkzPhysicsTabLine{$2.18-x_{\max}$,$-4x_{\max}$,$??$,$??$} \end{tikzpicture} \end{document} My questions for the experts: I initially defined \newcounter inside \tkzPhysicsTabInit, which caused an error when calling the table twice. I fixed this by declaring the counters globally in the package file and using \setcounter inside the macro to reset them. Is this the standard LaTeX best practice, or is there a more elegant way to handle local counters/variables in this context without polluting the global namespace? Is manually calculating coordinates using \pgfmathsetmacro the most efficient way to draw this grid, or would you recommend using TikZ libraries like matrix or integrating with packages like tabularray? Are there any other optimizations or best practices you would suggest to make this package more robust for general users? Thank you in advance for your insights!

  • How to draw a complex shaded ribbon with a central jewel using TikZ? [closed]
    by Natsu on August 2, 2026 at 7:48 am

    I am looking for guidance on how to recreate the attached image (image.png) entirely within LaTeX using TikZ. The image consists of two main complex elements: A red ribbon with intricate curves and realistic 3D-like gradient shading. A multi-faceted jewel/diamond in the center with sharp light reflections. Initially, I thought simulating this 3D effect in TikZ would be too complex, but following the community's helpful feedback and advice on providing a Minimal Working Example (MWE), I decided to tackle both the ribbon and the central jewel to demonstrate my progress. I managed to draw the ribbons using manual Bézier curves and custom shadings to simulate the folds. For the jewel, I used a clipping mask and layered semi-transparent polygons (opacity) to mimic the glass facets and light reflections. Here is my current MWE: \documentclass[tikz,border=5mm]{standalone} \usetikzlibrary{shadings,calc} \definecolor{ribbonred}{RGB}{215,10,28} \begin{document} \begin{tikzpicture}[x=3cm,y=3cm] \begin{scope} \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=150] (-0.463,-0.006) .. controls (-0.497,-0.017) and (-0.649,-0.048) .. (-0.672,-0.073) .. controls (-0.680,-0.110) and (-0.637,-0.134) .. (-0.601,-0.158) .. controls (-0.563,-0.147) and (-0.467,-0.035) .. (-0.445,-0.010) .. controls (-0.423,0.015) and (-0.464,-0.008) .. (-0.468,-0.008); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=150] (-0.188,-0.128) .. controls (-0.204,-0.135) and (-0.236,-0.149) .. (-0.281,-0.167) .. controls (-0.320,-0.207) and (-0.380,-0.306) .. (-0.372,-0.502) .. controls (-0.372,-0.717) and (-0.372,-0.842) .. (-0.562,-0.776) .. controls (-0.684,-0.438) and (-0.369,-0.102) .. (-0.231,-0.080) .. controls (-0.199,-0.102) and (-0.195,-0.127) .. (-0.188,-0.136); \fill[% top color=ribbonred!50!black, bottom color=ribbonred!50!black, middle color=ribbonred!80, shading angle=140] (-0.182,-0.067) .. controls (-0.437,-0.096) and (-0.598,-0.685) .. (-0.497,-0.794) .. controls (-0.664,-0.762) and (-0.983,-0.545) .. (-0.870,-0.355) .. controls (-0.742,-0.221) and (-0.518,-0.079) .. (-0.410,0.012) .. controls (-0.295,0.059) and (-0.217,-0.054) .. (-0.180,-0.069) .. controls (-0.142,-0.084) and (-0.196,-0.091) .. (-0.199,-0.095); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=30] (-0.178,0.212) .. controls (-0.206,0.278) and (-0.189,0.365) .. (-0.246,0.416) .. controls (-0.280,0.438) and (-0.328,0.400) .. (-0.328,0.369) .. controls (-0.315,0.330) and (-0.208,0.214) .. (-0.182,0.186) .. controls (-0.157,0.159) and (-0.178,0.209) .. (-0.177,0.213); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=30] (-0.160,0.197) .. controls (-0.221,0.247) and (-0.283,0.409) .. (-0.387,0.469) .. controls (-0.469,0.505) and (-0.508,0.420) .. (-0.521,0.365) .. controls (-0.488,0.312) and (-0.254,0.183) .. (-0.192,0.154) .. controls (-0.129,0.125) and (-0.166,0.190) .. (-0.161,0.198); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=90] (-0.141,0.178) .. controls (-0.350,0.409) and (-0.606,0.510) .. (-0.676,0.366) .. controls (-0.690,0.282) and (-0.678,0.169) .. (-0.660,0.115) .. controls (-0.634,0.025) and (-0.692,-0.075) .. (-0.665,-0.108) .. controls (-0.604,0.016) and (-0.319,-0.044) .. (-0.258,-0.059) .. controls (-0.171,-0.008) and (-0.165,0.163) .. (-0.147,0.207); \end{scope} \begin{scope}[shift={(-0.04, 0.03)}, xscale=-1, shift={(0.04, -0.03)}] \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=30] (-0.463,-0.006) .. controls (-0.497,-0.017) and (-0.649,-0.048) .. (-0.672,-0.073) .. controls (-0.680,-0.110) and (-0.637,-0.134) .. (-0.601,-0.158) .. controls (-0.563,-0.147) and (-0.467,-0.035) .. (-0.445,-0.010) .. controls (-0.423,0.015) and (-0.464,-0.008) .. (-0.468,-0.008); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=30] (-0.188,-0.128) .. controls (-0.204,-0.135) and (-0.236,-0.149) .. (-0.281,-0.167) .. controls (-0.320,-0.207) and (-0.380,-0.306) .. (-0.372,-0.502) .. controls (-0.372,-0.717) and (-0.372,-0.842) .. (-0.562,-0.776) .. controls (-0.684,-0.438) and (-0.369,-0.102) .. (-0.231,-0.080) .. controls (-0.199,-0.102) and (-0.195,-0.127) .. (-0.188,-0.136); \fill[% top color=ribbonred!50!black, bottom color=ribbonred!50!black, middle color=ribbonred!80, shading angle=30] (-0.182,-0.067) .. controls (-0.437,-0.096) and (-0.598,-0.685) .. (-0.497,-0.794) .. controls (-0.664,-0.762) and (-0.983,-0.545) .. (-0.870,-0.355) .. controls (-0.742,-0.221) and (-0.518,-0.079) .. (-0.410,0.012) .. controls (-0.295,0.059) and (-0.217,-0.054) .. (-0.180,-0.069) .. controls (-0.142,-0.084) and (-0.196,-0.091) .. (-0.199,-0.095); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=160] (-0.178,0.212) .. controls (-0.206,0.278) and (-0.189,0.365) .. (-0.246,0.416) .. controls (-0.280,0.438) and (-0.328,0.400) .. (-0.328,0.369) .. controls (-0.315,0.330) and (-0.208,0.214) .. (-0.182,0.186) .. controls (-0.157,0.159) and (-0.178,0.209) .. (-0.177,0.213); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=160] (-0.160,0.197) .. controls (-0.221,0.247) and (-0.283,0.409) .. (-0.387,0.469) .. controls (-0.469,0.505) and (-0.508,0.420) .. (-0.521,0.365) .. controls (-0.488,0.312) and (-0.254,0.183) .. (-0.192,0.154) .. controls (-0.129,0.125) and (-0.166,0.190) .. (-0.161,0.198); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=90] (-0.141,0.178) .. controls (-0.350,0.409) and (-0.606,0.510) .. (-0.676,0.366) .. controls (-0.690,0.282) and (-0.678,0.169) .. (-0.660,0.115) .. controls (-0.634,0.025) and (-0.692,-0.075) .. (-0.665,-0.108) .. controls (-0.604,0.016) and (-0.319,-0.044) .. (-0.258,-0.059) .. controls (-0.171,-0.008) and (-0.165,0.163) .. (-0.147,0.207); \end{scope} \begin{scope} \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred, shading angle=0] (-0.189,-0.118) .. controls (-0.262,-0.210) and (-0.334,-0.412) .. (-0.198,-0.646) .. controls (-0.186,-0.647) and (0.020,-0.234) .. (-0.118,-0.126) .. controls (-0.131,-0.134) and (-0.179,-0.123) .. (-0.191,-0.123); \fill[% top color=ribbonred!20!black, bottom color=ribbonred, shading angle=60] (-0.131,-0.812) .. controls (-0.045,-0.966) and (0.098,-1.214) .. (0.060,-1.606) .. controls (0.142,-1.512) and (0.204,-1.281) .. (0.179,-1.065) .. controls (0.245,-1.127) and (0.337,-1.249) .. (0.337,-1.479) .. controls (0.516,-1.078) and (0.167,-0.702) .. (0.064,-0.552) .. controls (-0.015,-0.442) and (-0.101,-0.777) .. (-0.136,-0.819); \fill[% top color=ribbonred!20!black, bottom color=ribbonred!20!black, middle color=ribbonred!90, shading angle=0] (-0.167,-0.091) .. controls (0.030,-0.372) and (-0.401,-0.822) .. (-0.420,-1.051) .. controls (-0.489,-1.248) and (-0.417,-1.580) .. (-0.277,-1.714) .. controls (-0.351,-1.499) and (-0.303,-1.285) .. (-0.258,-1.233) .. controls (-0.250,-1.456) and (-0.057,-1.685) .. (0.073,-1.730) .. controls (-0.079,-1.540) and (-0.159,-1.035) .. (0.050,-0.742) .. controls (0.218,-0.479) and (0.235,-0.219) .. (0.058,-0.085) .. controls (0.019,0.022) and (-0.140,-0.101) .. (-0.179,-0.104); \end{scope} \begin{scope}[shift={(-0.04, 0.03)}] \shadedraw[draw=ribbonred, very thick, inner color=white, outer color=black!85] (0,0) circle (0.25); \begin{scope} \clip (0,0) circle (0.24); \def\rTable{0.12} \def\rEdge{0.25} \fill[black, opacity=0.35] (67.5:\rTable) -- (112.5:\rTable) -- (90:\rEdge) -- cycle; \fill[black, opacity=0.5] (202.5:\rTable) -- (247.5:\rTable) -- (225:\rEdge) -- cycle; \fill[black, opacity=0.2] (247.5:\rTable) -- (292.5:\rTable) -- (270:\rEdge) -- cycle; \fill[white, opacity=0.6] (22.5:\rTable) -- (67.5:\rTable) -- (45:\rEdge) -- cycle; \fill[white, opacity=0.4] (292.5:\rTable) -- (337.5:\rTable) -- (315:\rEdge) -- cycle; \fill[white, opacity=0.7] (112.5:\rTable) -- (135:\rEdge) -- (180:\rEdge) -- cycle; \fill[white, opacity=0.8] (0,0) -- (45:0.1) -- (0:0.15) -- cycle; \fill[white, opacity=0.5] (0,0) -- (135:0.1) -- (180:0.15) -- cycle; \draw[white, thin, opacity=0.7] (22.5:\rTable) \foreach \a in {67.5, 112.5, 157.5, 202.5, 247.5, 292.5, 337.5} { -- (\a:\rTable) } -- cycle; \foreach \a in {22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, 337.5} { \draw[white, thin, opacity=0.6] (\a:\rTable) -- (\a+22.5:\rEdge); \draw[white, thin, opacity=0.5] (\a:\rTable) -- (\a-22.5:\rEdge); } \draw[white, thin, opacity=0.8] (0:\rEdge) -- (180:\rEdge); \draw[white, thin, opacity=0.4] (90:\rEdge) -- (270:\rEdge); \end{scope} \tikzset{sparkle/.pic={ \fill[white, opacity=0.9] (0,0.03) .. controls (0.005,0.005) .. (0.03,0) .. controls (0.005,-0.005) .. (0,-0.03) .. controls (-0.005,-0.005) .. (-0.03,0) .. controls (-0.005,0.005) .. cycle; }} \pic at (0.08, 0.12) {sparkle}; \pic[scale=0.7] at (-0.12, 0.05) {sparkle}; \pic[scale=0.5] at (-0.05, -0.15) {sparkle}; \pic[scale=0.8] at (0.15, -0.08) {sparkle}; \end{scope} \end{tikzpicture} \end{document} And here is the resulting output I am very happy with the jewel, but I am looking for advice on how to improve the overall code structure (e.g., making the ribbon code more modular). Additionally, I really struggled with color coordination and picking the right shades for the gradients. If anyone could help me adjust the color palette to make the ribbon look more naturally glossy and realistic, I would be very grateful. I also want to thank kabenyuk for their excellent answer which showed how to modularize the ribbon drawing! Any further improvements or tips on combining these elements effectively would be greatly appreciated.

  • Stacking multiple number lines on top of each other
    by Muhannad Al Ayoubi on August 1, 2026 at 9:09 am

    I made the following diagram, which is supposed to depict how the intersection of two intervals can be determined. However, as you can see, I could include only one number line, which makes the diagram look rather empty, in my opinion. Is there a away to draw two more number lines above the original one, aligned with the "flying" blue intervals? I have thought about drawing three separate tikz pictures above each other, but then I can't draw the red dashed line, and it would also make it difficult to control the invisible space taken by the y-axis. \documentclass{book} \usepackage{pgfplots} \begin{document} \begin{tikzpicture}[every node/.style={font=\small},] \begin{axis}[ clip=false, axis x line=middle, axis y line=none, x axis line style={<->}, xmin=-3.4, xmax=7.4, ymin=-.5, ymax=3, xtick distance=1, x=.6cm, y=1cm, ] % Red dashed lines \draw [red,dashed] (axis cs:-1,0) -- (axis cs:-1,2.2) (axis cs:6,0) -- (axis cs:6,2.2); % Points \addplot[only marks,mark options={fill=white}] coordinates {(6,2) (-1,1) (6,0) (-1,0)}; % Uppermost number line for x < 6 \draw[<-,very thick] (axis cs:-3,2) -- (axis cs:6,2); % Middle number line for x > -1 \draw[->,very thick] (axis cs:-1,1) -- (axis cs:7,1); % Lower number line for intersection of inequalities \draw[very thick] (axis cs:-1,0) -- (axis cs:6,0); % Labels \draw (axis cs:8,2) node[right]{$x<6$} (axis cs:8,1) node[right]{$x>-1$} (axis cs:8,0) node[right]{$x<6$ and $x>-1$, or simply $-1<x<6$.}; \end{axis} \end{tikzpicture} \end{document} Here is what it looks like (note I have removed color and font information from the code to keep things simple).

  • Does plain TikZ have a built-in way to reuse intermediate mathematical calculations across `plot` dimensions?
    by Jasper on July 31, 2026 at 3:29 pm

    Does plain TikZ have a built-in way to reuse intermediate mathematical calculations across plot dimensions? I mean I could just use a foreach loop and pgfmathsetmacro, but that's quite intensive. Is this built in to plot? If not, should/could it be? I mean, I doubt it, but I also doubted that my previous question had a good solution - which I, to my pleasant surprise, turned out to be wrong about. % Source - https://tex.stackexchange.com/a/764941 % Posted by kabenyuk, modified (!) by Jasper. See post 'Timeline' for change history % Retrieved 2026-07-31, License - CC BY-SA 4.0 \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw plot[ domain=0:4, declare function={ f(\t)=(\t)^2-(\t)^3; } ] ( \x, {f(\x-2)}, % A third component requires that I recompute some % values which have already been computed. {f(\x-2) - \x} ) ; \end{tikzpicture} \end{document}

  • Very slow compilation due to complex TikZ page background: How to optimize?
    by Natsu on July 30, 2026 at 11:39 pm

    I am working on a document where I created a custom page border and headers/footers using TikZ and eso-pic. However, the document is extremely heavy to process. The compilation time is very slow, and it gets significantly worse as the number of pages increases. Is there a more efficient way to write this code? For example, is there a way to render the background only once and reuse it across all pages (like saving it to a box), instead of drawing these complex paths and loops on every single page? Here is my MWE (compiled with XeLaTeX/LuaLaTeX): \documentclass[a4paper]{report} \usepackage[right=1.1cm,left=1.3cm,top=2.5cm,bottom=2cm,foot=0mm,head=0mm]{geometry} \usepackage{amsmath,amsfonts,eso-pic,amssymb,mathrsfs,tikz,fancyhdr,multicol,pifont,ifthen,lastpage,graphicx} \usepackage[most]{tcolorbox} \usetikzlibrary{arrows,shapes,calc} \parindent=0mm \colorlet{col1}{blue} \colorlet{col2}{col1!50} \pagestyle{empty} \newcounter{tabb} \newcommand{\shape}[2][1]{\setcounter{tabb}{1}\tabcolsep=0mm\begin{tabular}{c} \whiledo{\thetabb<#2}{\hskip-3pt% \tikz{\path[top color=col2,bottom color=col2,middle color=white] (3.9cm,-.7)rectangle(7.1cm,7mm); \draw[.!50!col1] (3.9,-.7)--(7.1,-.7)(3.9,.7)--(7.1,.7); \draw[line width=3pt,smooth,inner color=white,outer color=gray,draw=.!25!gray] plot[domain=3.9:7.1] (\x,{sin deg(\x)}) plot[domain=3.9:7.1] (\x,{cos deg(\x)}); \draw[transform canvas={yscale=#1},line width=3pt,smooth,inner color=white,outer color=gray,draw=.!25!gray] plot[domain=3.9:7.1] (\x,{sin deg(\x)}) plot[domain=3.9:7.1] (\x,{cos deg(\x)});}\stepcounter{tabb}}% \end{tabular}} \AddToShipoutPicture{ \begin{tikzpicture}[overlay,remember picture] \coordinate (1) at ([shift={(-.8,-1.25)}]current page.north east); \coordinate (2) at ([shift={(.8,-1.25)}]current page.north west); \coordinate (3) at ([shift={(.8,1.25)}]current page.south west); \coordinate (4) at ([shift={(-.8,1.25)}]current page.south east); \path (2)--node[scale=0.2,rotate=90,inner sep=0mm]{\shape{41}}(3); \path (1)--node[scale=0.2,rotate=90,inner sep=0mm]{\shape{41}}(4); \coordinate (5)at ($(1)!1/4!(2)$); \coordinate (6)at ($(1)!3/4!(2)$); \coordinate (7)at ($(4)!1/4!(3)$); \coordinate (8)at ($(4)!3/4!(3)$); \path (1)--node[scale=0.2,inner sep=0mm]{\shape{4}}(5); \path (2)--node[scale=0.2,inner sep=0mm]{\shape{4}}(6); \path (4)--node[scale=0.2,inner sep=0mm]{\shape{4}}(7); \path (3)--node[scale=0.2,inner sep=0mm]{\shape{4}}(8); \foreach \i/\j/\k in {1/1/1,2/-1/1,3/-1/-1,4/1/-1}{ \node [inner sep=0mm,left] at (\i) {\scalebox{\j}[\k]{% \tikz[transform canvas={shift={(-.5mm,-.4mm)}}]{ \coordinate (a)at (0,0); \draw[inner color=white,outer color=gray]([shift={(-2mm,1mm)}]a)to[out=250,in=-45]([xshift=-1.6cm,yshift=-.8mm]a)-|+(.14,2mm)to[out=-45,in=240]([yshift=-3mm,xshift=-2mm]a); \draw[inner color=white,outer color=gray] ([yshift=-.75cm,xshift=1.5mm]a)to[out=40,in=-90]([xshift=-1mm,yshift=2mm]a)--([xshift=-3mm,yshift=2mm]a)to[out=-90,in=10]([shift={(-1mm,-.75cm)}]a); }% }}; \node[inner sep=0mm,scale=2,text=col1] at (\i){% \includegraphics[width=.5cm,height=.5cm]{im1}% }; } \node[text width=0.75\textwidth,inner sep=0mm,baseline={(1.east)}] at ($(1)!.5!(2)$){ %\begin{otherlanguage}{arabic} \begin{tcolorbox}[enhanced,nobeforeafter,right=5mm,left=5mm,frame empty,fontupper=\bfseries\large,interior code={ \path[draw=col1,line width=.8pt,bottom color=col1!50,top color=col1!50,middle color=white] ([yshift=1.5mm]interior.east)to[out=180,in=0]([xshift=-2cm]interior.north east)--([xshift=2cm]interior.north west)to[out=180, in=0]([yshift=1.5mm]interior.west)to[bend left]([yshift=-1.5mm]interior.west)to[out=0,in=180]([xshift=2cm]interior.south west)--([xshift=-2cm]interior.south east)to[out=0,in=180]([yshift=-1.5mm]interior.east)to[bend left]cycle; \path(interior.east)-- node[pos=0.33,yscale=.8,xscale=.5,inner sep=0mm]{\colorlet{gray}{col1}\shape[-1]{2}} node[pos=0.69,yscale=.8,xscale=.5,inner sep=0mm]{\colorlet{gray}{col1}\shape[-1]{2}}(interior.west); }] text left \hfill text center \hfill text right \end{tcolorbox}% %\end{otherlanguage}% \vglue-\baselineskip }; \node[text width=0.75\textwidth,inner sep=0mm] at ($(4)!.5!(3)$){ \begin{tcolorbox}[enhanced,nobeforeafter,right=5mm,left=5mm,frame empty,top=0mm,bottom=0mm,fontupper=\bfseries\large,interior code={ \path[draw=col1,line width=.8pt,bottom color=col1!50,top color=col1!50,middle color=white] ([yshift=1.5mm]interior.east)to[out=180,in=0]([xshift=-2cm]interior.north east)--([xshift=2cm]interior.north west)to[out=180, in=0]([yshift=1.5mm]interior.west)to[bend left]([yshift=-1.5mm]interior.west)to[out=0,in=180]([xshift=2cm]interior.south west)--([xshift=-2cm]interior.south east)to[out=0,in=180]([yshift=-1.5mm]interior.east)to[bend left]cycle; }]\centering Page 1 of 1 \end{tcolorbox}% %\end{otherlanguage}% \vglue-\baselineskip }; \end{tikzpicture} } \begin{document} hey \end{document} image im1: Note: I have attached the image (im1) used in the document. Also, I am using some local Arabic fonts in my code (Aljazeera.ttf and Al Qalam Quran Majeed Web.ttf). If you want to test the code on your machine, you can simply comment them out or replace them with any standard font (like Amiri). My main problem is that compiling this document is extremely slow because of the complex TikZ background (especially the loops and smooth paths). The processing time gets heavier and heavier with every new page added. Is there a way to optimize this? For example, is it possible to render this background only once (saving it into a box) and reuse it on every page to drastically reduce the compilation time? Any help or optimized code would be highly appreciated. Thank you! EDIT/UPDATE: I sincerely apologize for my previous code. I realized it contained local Arabic fonts and packages (polyglossia) which made it impossible for you to compile and test. I have completely cleaned up the code. It is now a proper Minimal Working Example (MWE) using only standard packages and example-image. My issue is that this document is extremely slow to compile because of the complex TikZ background (the loops, \whiledo, and smooth curves). The compilation time increases heavily with every new page. As pointed out in the comments, I need to separate the static parts (the complex borders/decorations) from the variable parts (like the page number), but my code is too entangled with nested tikzpictures and tcolorbox. Could someone please provide a structural example of how to redesign this so the heavy background is drawn/saved only once, drastically reducing compilation time? Here is the clean, compilable MWE (you can test it with pdfLaTeX): \documentclass[a4paper]{report} \usepackage[right=1.1cm,left=1.3cm,top=2.5cm,bottom=2cm,foot=0mm,head=0mm]{geometry} \usepackage{amsmath,amsfonts,eso-pic,amssymb,mathrsfs,tikz,fancyhdr,multicol,pifont,ifthen,lastpage,graphicx} \usepackage[most]{tcolorbox} \usetikzlibrary{arrows,shapes,calc} \parindent=0mm \colorlet{col1}{blue} \colorlet{col2}{col1!50} \pagestyle{empty} \newcounter{tabb} \newcommand{\shape}[2][1]{\setcounter{tabb}{1}\tabcolsep=0mm\begin{tabular}{c} \whiledo{\thetabb<#2}{\hskip-3pt% \tikz{\path[top color=col2,bottom color=col2,middle color=white] (3.9cm,-.7)rectangle(7.1cm,7mm); \draw[.!50!col1] (3.9,-.7)--(7.1,-.7)(3.9,.7)--(7.1,.7); \draw[line width=3pt,smooth,inner color=white,outer color=gray,draw=.!25!gray] plot[domain=3.9:7.1] (\x,{sin deg(\x)}) plot[domain=3.9:7.1] (\x,{cos deg(\x)}); \draw[transform canvas={yscale=#1},line width=3pt,smooth,inner color=white,outer color=gray,draw=.!25!gray] plot[domain=3.9:7.1] (\x,{sin deg(\x)}) plot[domain=3.9:7.1] (\x,{cos deg(\x)});}\stepcounter{tabb}}% \end{tabular}} \AddToShipoutPicture{ \begin{tikzpicture}[overlay,remember picture] \coordinate (1) at ([shift={(-.8,-1.25)}]current page.north east); \coordinate (2) at ([shift={(.8,-1.25)}]current page.north west); \coordinate (3) at ([shift={(.8,1.25)}]current page.south west); \coordinate (4) at ([shift={(-.8,1.25)}]current page.south east); \path (2)--node[scale=0.2,rotate=90,inner sep=0mm]{\shape{41}}(3); \path (1)--node[scale=0.2,rotate=90,inner sep=0mm]{\shape{41}}(4); \coordinate (5)at ($(1)!1/4!(2)$); \coordinate (6)at ($(1)!3/4!(2)$); \coordinate (7)at ($(4)!1/4!(3)$); \coordinate (8)at ($(4)!3/4!(3)$); \path (1)--node[scale=0.2,inner sep=0mm]{\shape{4}}(5); \path (2)--node[scale=0.2,inner sep=0mm]{\shape{4}}(6); \path (4)--node[scale=0.2,inner sep=0mm]{\shape{4}}(7); \path (3)--node[scale=0.2,inner sep=0mm]{\shape{4}}(8); \foreach \i/\j/\k in {1/1/1,2/-1/1,3/-1/-1,4/1/-1}{ \node [inner sep=0mm,left] at (\i) {\scalebox{\j}[\k]{% \tikz[transform canvas={shift={(-.5mm,-.4mm)}}]{ \coordinate (a)at (0,0); \draw[inner color=white,outer color=gray]([shift={(-2mm,1mm)}]a)to[out=250,in=-45]([xshift=-1.6cm,yshift=-.8mm]a)-|+(.14,2mm)to[out=-45,in=240]([yshift=-3mm,xshift=-2mm]a); \draw[inner color=white,outer color=gray] ([yshift=-.75cm,xshift=1.5mm]a)to[out=40,in=-90]([xshift=-1mm,yshift=2mm]a)--([xshift=-3mm,yshift=2mm]a)to[out=-90,in=10]([shift={(-1mm,-.75cm)}]a); }% }}; \node[inner sep=0mm,scale=2,text=col1] at (\i){% \includegraphics[width=.5cm,height=.5cm]{im1}% }; } \node[text width=0.75\textwidth,inner sep=0mm,baseline={(1.east)}] at ($(1)!.5!(2)$){ %\begin{otherlanguage}{arabic} \begin{tcolorbox}[enhanced,nobeforeafter,right=5mm,left=5mm,frame empty,fontupper=\bfseries\large,interior code={ \path[draw=col1,line width=.8pt,bottom color=col1!50,top color=col1!50,middle color=white] ([yshift=1.5mm]interior.east)to[out=180,in=0]([xshift=-2cm]interior.north east)--([xshift=2cm]interior.north west)to[out=180, in=0]([yshift=1.5mm]interior.west)to[bend left]([yshift=-1.5mm]interior.west)to[out=0,in=180]([xshift=2cm]interior.south west)--([xshift=-2cm]interior.south east)to[out=0,in=180]([yshift=-1.5mm]interior.east)to[bend left]cycle; \path(interior.east)-- node[pos=0.33,yscale=.8,xscale=.5,inner sep=0mm]{\colorlet{gray}{col1}\shape[-1]{2}} node[pos=0.69,yscale=.8,xscale=.5,inner sep=0mm]{\colorlet{gray}{col1}\shape[-1]{2}}(interior.west); }] text left \hfill text center \hfill text right \end{tcolorbox}% %\end{otherlanguage}% \vglue-\baselineskip }; \node[text width=0.75\textwidth,inner sep=0mm] at ($(4)!.5!(3)$){ \begin{tcolorbox}[enhanced,nobeforeafter,right=5mm,left=5mm,frame empty,top=0mm,bottom=0mm,fontupper=\bfseries\large,interior code={ \path[draw=col1,line width=.8pt,bottom color=col1!50,top color=col1!50,middle color=white] ([yshift=1.5mm]interior.east)to[out=180,in=0]([xshift=-2cm]interior.north east)--([xshift=2cm]interior.north west)to[out=180, in=0]([yshift=1.5mm]interior.west)to[bend left]([yshift=-1.5mm]interior.west)to[out=0,in=180]([xshift=2cm]interior.south west)--([xshift=-2cm]interior.south east)to[out=0,in=180]([yshift=-1.5mm]interior.east)to[bend left]cycle; }]\centering Page 1 of 1 \end{tcolorbox}% %\end{otherlanguage}% \vglue-\baselineskip }; \end{tikzpicture} } \begin{document} hey \end{document}

  • Positioning all elements of a picture created with tikzpicture customly [closed]
    by user446112 on July 30, 2026 at 8:35 am

    I wonder how an entire picture created with tikzpicture can be positioned in a Beamer slide, that is, my purpose is to positioning all tikzpicture in the slide with custom precision (e.g., by using coordinates). I tried \hspace and \vspace but the results are not good. Find my code below: \documentclass{beamer} \usepackage{tikz} \usetikzlibrary{tikzmark,calc,positioning,fit,arrows,shapes,backgrounds,shapes.geometric,arrows.meta,patterns.meta,decorations.pathreplacing} \begin{document} \begin{frame} \begin{tikzpicture} \fill[blue] (0,0) circle (0.5); \fill[red] (1,0) circle (0.5); \end{tikzpicture} \end{frame} \end{document} (compiled via Lua LaTeX). With thanks

  • How to include a TikZ .tex file in a large document? I keep getting "LaTeX Error: Environment tikzpicture undefined."
    by ali bab613 on July 30, 2026 at 1:28 am

    I have a fairly complex document, but I extracted this MWE from it. I'm including a similar file tree as what's in the actual document to ensure that its as close to my document as possible. For extra context, I am using Overleaf, and compiling using LuaLaTeX (in case that's relevant). main.tex has this: \documentclass{article} \usepackage{standalone} \usepackage{hyperref} \begin{document} \input{Chapter1} \end{document} The content of Chapter1.tex is as follows: \input{Images/Chapter 1/Tester} and the Tester.tex file referenced is as follows: \documentclass{standalone} \usepackage{tikz} \usepackage{adjustbox} \begin{document} \begin{adjustbox}{margin=2} \begin{tikzpicture} \node [draw,circle,black,scale=0.7,minimum width=46] at (0,0) {Tester}; \end{tikzpicture} \end{adjustbox} \end{document} I should note that when I compile Tester.tex, it generates the circle fine. When I compile main.tex, however, it gives me the line of code itself in the pdf: I was using the standalone package as suggested in the answers to this question, but it was not enough. Any advice is appreciated!

  • How to better design the binary switch option in TikZ case?
    by Explorer on July 1, 2026 at 7:31 am

    I have the following code modified from my previous question: % https://tex.stackexchange.com/a/96970 % https://tex.stackexchange.com/a/762399 \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{arrows.meta,bending,nfold,ext.nodes,decorations.markings} \makeatletter \tikzset{ foo/.tip={Straight Barb[harpoon,swap,length=5pt]}, mystyle/.style={thick,shorten >=2pt,shorten <=2pt}, offset/.code= \tikz@addoption{% \pgfgetpath\tikz@temp \pgfsetpath\pgfutil@empty \pgfoffsetpath\tikz@temp{#1} }, dualharpoon/.style={ draw=none, postaction={path only,draw,foo-,mystyle,offset=+#1ex}, postaction={path only,draw,-foo,mystyle,offset=-#1ex}, postaction={decorate, decoration={markings, mark=at position 0.5 with { \begin{scope}[yshift=+#1ex] \draw[-,line cap=round,thick] ++ (-.15cm,-.15cm) -- (+.15cm,+.15cm); % \draw[-,line cap=round,thick] ++ (-.15cm,+.15cm) -- (+.15cm,-.15cm); \end{scope} \begin{scope}[yshift=-#1ex] \draw[-,line cap=round,thick] ++ (-.15cm,-.15cm) -- (+.15cm,+.15cm); % \draw[-,line cap=round,thick] ++ (-.15cm,+.15cm) -- (+.15cm,-.15cm); \end{scope} }}, }, }, dualharpoon/.default=.75, } \makeatother \begin{document} \begin{tikzpicture}[ Qstyle/.style={ dualharpoon, ext/auto with offset, % default true ext/auto offset=1ex, auto, }] \node[draw,circle,fill=teal] (A) at (0,1) {A}; \node[draw,circle,fill=magenta] (B) at (0,-1) {B}; \node[draw,circle,fill=cyan] (C) at (2.5,.5) {C}; \draw[magenta,Qstyle] (A) to[bend right] node {$\Delta$} node[swap]{$\nabla$} (B); \draw[teal,Qstyle] (B) to[bend right] node {$f(x)$} node[swap]{$g(x)$} (C); \draw[orange,Qstyle] (A) -- node {$x$} node[swap]{$y$} (C); \end{tikzpicture} \end{document} Now I want two control switches: which one to place slash: positive offset one? negetive one? or both? or none? which direction to put slash? forward: \draw[-,line cap=round,thick] ++ (-.15cm,-.15cm) -- (+.15cm,+.15cm); and \draw[-,line cap=round,thick] ++ (-.15cm,-.15cm) -- (+.15cm,+.15cm); backward: \draw[-,line cap=round,thick] ++ (-.15cm,+.15cm) -- (+.15cm,-.15cm); or \draw[-,line cap=round,thick] ++ (-.15cm,+.15cm) -- (+.15cm,-.15cm);? Or in other word, I want the syntax for example: \draw[magenta,Qstyle,slash side=both,slash direction=backward] (A) to[bend right] node {$\Delta$} node[swap]{$\nabla$} (B); \draw[teal,Qstyle,slash side=positive,slash direction=forward] (B) to[bend right] node {$f(x)$} node[swap]{$g(x)$} (C); \draw[orange,Qstyle,slash side=none] (A) -- node {$x$} node[swap]{$y$} (C); I was after a neat option syntax to encapsulate the logic above. Any suggestions?

  • How to avoid duplicate chapter title and absolutely position chapter title with TikZ
    by Chen Mortenfeld on June 12, 2025 at 7:50 pm

    I'm customizing chapter titles in my book using the titlesec and tikz packages. For special chapters like the "Preface", I want to: Show a custom TikZ-styled title box that is positioned exactly \TitleBoxOffset below the top of the page (absolute positioning, not relative). Avoid having the chapter title (e.g., "Preface") appear twice on the page — once inside my TikZ box and once from LaTeX's default chapter title mechanism. So basically "Preface" appears twice, and the location is set manually. Here's my code in the .sty file: \usepackage[explicit]{titlesec} \usepackage{tikz} \usepackage{xcolor} \usepackage{etoolbox} % for \IfStrEq \newcommand{\CurrentChapterTitle}{} \newlength{\ChapterTopSkip} \newcommand{\ChapterHook}[1]{% \renewcommand{\CurrentChapterTitle}{#1}% \IfStrEq{#1}{Preface}{% \titleformat{\chapter} [block] {\centering} {} % no label {0pt} {% \begin{tikzpicture} \node[ draw=lightblue, line width=1pt, rounded corners=10pt, minimum width=0.8\linewidth, minimum height=2cm, align=center, fill=white, fill opacity=1, text opacity=1 ] {\scalebox{1.4}{\textcolor{lightblue}{\Huge{#1}}}}; \end{tikzpicture} } % \titlespacing*{\chapter}{0pt}{-\topskip}{20pt} \titlespacing*{\chapter}{0pt}{-95pt}{20pt} } {% \titleformat{\chapter}[block] {\normalfont\scshape\Huge\centering} {\fontsize{140pt}{140pt}\selectfont\thechapter\\} {0pt} {\normalfont\scshape\Huge\centering #1} }% } % % Patch \chapter to call ChapterHook \let\oldchapter\chapter \renewcommand{\chapter}[1]{% \ChapterHook{#1}% \oldchapter{#1}% } % Suppress LaTeX’s default \@makechapterhead \makeatletter \renewcommand{\@makechapterhead}[1]{} \makeatother Update: I updated the code block to include the packages. Thanks to the comments, I managed to make the word "Preface" appear only once, by using: \usepackage[explicit]{titlesec} see the update code. Now my only issue is the position of the title that I define manually — I want it to be at position 0 relative to the page boundaries, and then I’ll subtract a fixed predefined offset from it. Thank you!

  • Drawing the Steinmetz solid with TikZ
    by Knudsen on September 13, 2024 at 10:48 pm

    I want to draw the Steinmetz solid, the volume enclosed by two cilinder of same radius intersecting orthogonaly. I have so far been able to draw the circles in 3D and the lines till their intersecting point. \documentclass{standalone} \usepackage{tikz,tikz-3dplot} \begin{document} \def\rotx{60} \def\rotz{110} \def\eps{0.5} \tdplotsetmaincoords{\rotx}{\rotz} \begin{tikzpicture}[tdplot_main_coords][scale=0.75] \tikzstyle{every node}=[font=\small] % The axis: \draw[dashed,-latex] (-5,0,0) -- (6,0,0) node[anchor=north east]{$x$}; \draw[dashed,-latex] (0,-5,0) -- (0,6,0) node[anchor=north west]{$y$}; \draw[dashed,-latex] (0,0,-5) -- (0,0,6) node[anchor=south]{$z$}; \draw [very thick,blue](0,-3-\eps,0) [y={(0,0,1)}] circle (3); \draw [very thick,blue](0,3+\eps,0) [y={(0,0,1)}] circle (3); \draw [very thick,red](-3-\eps,0,0) [x={(0,0,1)}] circle (3); \draw [very thick,red](3+\eps,0,0) [x={(0,0,1)}] circle (3); \foreach \angle in {0,10,...,360} { %calculate the sine and cosine of the angle \tdplotsinandcos{\sintheta}{\costheta}{\angle}% % draw the lines \draw[thin, blue] (3*\costheta,-3-\eps, 3*\sintheta) -- (3*\costheta,{-3*abs(\costheta)},3*\sintheta) (3*\costheta,{3*abs(\costheta)},3*\sintheta) -- (3*\costheta,3+\eps, 3*\sintheta); \draw[thin, red] (-3-\eps, 3*\costheta,3*\sintheta) -- ({-3*abs(\costheta)},3*\costheta,3*\sintheta) ({3*abs(\costheta)},3*\costheta,3*\sintheta) -- (3+\eps, 3*\costheta,3*\sintheta); } \end{tikzpicture} \end{document} that renders as: but I am taking a black eye at drawing the intersecting elipses and hiding the lines that are not supposed to be visible. Are there automated ways to do this in TikZ and even to do a better picture of the solid, possibly using the shaded surface? Added Sep 14, 2024: After realizing that it would be harder to get a good looking picture from TikZ and a prompts from @Jasper and from @PauloNey, I went to dig a bit deeper on Asymptote. It became imediate clear that the syntax for 3D was easier and the results a lot better. With the code \documentclass{standalone} \usepackage[inline]{asymptote} \begin{document} \thispagestyle{empty} \begin{asy} import graph3; import solids; pen myBlue = cmyk(1.00, 0.15, 0, 0); pen myRed = cmyk(0, 1.00, 1.00, 0); size(0,150); currentprojection=orthographic(1,1/1.7,1/1.6); // usage revolution r = cylinder(start,radius,length,ax); revolution r=cylinder(O,1,2.8,X); draw(surface(r),myBlue,render(merge=true)); revolution r=cylinder((1.4,-1.4,0),1,2.8,Y); draw(surface(r),myRed,render(merge=true)); \end{asy} \end{document} one can get: but it is clear that ligthing is happening in one cylinder as if the other were not there, that is, on each independent of the other.

  • TikZ: Shapes with an angular colour gradient
    by StormyTeacup on April 18, 2024 at 2:05 pm

    Cross-posting from Stack Overflow: https://stackoverflow.com/q/78347764/2777074 Good people! I'm trying to draw some shapes with an angular colour gradient, but I am unable to find the general syntax for how fill a shape like that. I'm going to need to draw an awful lot of these diagrams, but to give you an idea of the basic way I want these things to look like when they're finished, I am attaching this picture: So, what I want is something so that I can specify "the gradient starts with colour X at angle A, and ends with colour Y at angle B". Does TikZ picture have such a function, or is it necessary to define something on one's own? Look forward to your responses! The only thing I've been able to come up with would be to use the method described in this answer to create a circular shape as a background, then to "hide" most of it with white with a cut-out of my shape remaining, but the problem with this approach is not only that it's kind of inelegant, it also will not work if I need to have several shapes next to one another. https://stackoverflow.com/questions/72813749/tikz-fill-a-circle-with-shading-color-by-angle EDIT: It being requested that I add some code snippet, I have put together this one, which produces the figure I have in mind, albeit without the desired gradient: \begin{tikzpicture} \draw[thick, arrows=<->] (-5,0)--(5,0); \draw[thick, arrows=<->] (0,-5)--(0,5); \draw[fill=red, draw=none] (2.5,0) arc (0:225:2.5) -- (225:2.2) -- (243:3) -- (225:3.8)--(225:3.5) arc (225:0:3.5) -- cycle; \draw[fill=blue, draw=none] (290:2.5) arc (290:335:2.5) -- (335:2.2) -- (353:3) -- (335:3.8) -- (335:3.5) arc (335:290:3.5) -- cycle; \end{tikzpicture} The image produced looks as follows:

  • How to build cylinders similar to this, but in reverse?
    by TCR on April 8, 2024 at 8:06 pm

    How to build cylinder in tikz like shown in this example The example above builds a set of ever-larger cylinders on top of each other with texts on the side, starting at the bottom. The example output and code is replicated here. The source is the link above. \documentclass[border=3.14pt]{standalone} \usepackage{pgfplots} \definecolor{myellow}{RGB}{228,212,0} \definecolor{mgreen}{RGB}{5,104,57} \newcommand\funnel[3]{% \pgfmathsetmacro\mwid{(2+\xi*.7)} \pgfmathsetmacro\marc{\mwid-.4} \begin{scope}[% shift={(0,#1)}, line width=.05pt, %x=5mm, %scale=1.\xi, yshift=\xi*12 ] \draw[black,bottom color=#2, top color=#2] (-\mwid,0) -- (-\mwid+.4,-1) arc (190:350:\marc cm and 5mm) -- (\mwid,0); \draw[black,fill=#3] (0,0) ellipse (\mwid cm and 5mm); \path (-\mwid,0) -- (-\mwid+.4,-1) coordinate[midway] (a\xi); \end{scope} } \begin{document} \begin{tikzpicture}[ latent/.style={% ,circle ,draw ,thick ,minimum size=10mm } ] \foreach \text [% count=\xi starting from 0, evaluate=\xi as \shadecolor using int(25*\xi), evaluate=\xi as \coord using int(\xi-12) ] in {% Discuss and conclude\\overall findings, Combine the data\\\tiny\itshape (synthesis or meta-analysis), Assess the quality\\of the studies, Extract data from the studies }{% \funnel{\coord}{mgreen!\shadecolor !myellow}{mgreen!\shadecolor !myellow} \node[align=right, anchor=east, inner sep=10pt, font=\scriptsize, text width=2cm] at (a\xi) {\text}; } \end{tikzpicture} \end{document} I am looking for two things: A set of an arbitrary number of ever-larger cylinders on top of each other with texts on the side, starting from the top. Following the ever-larger cylinders, a set of an arbitrary number of ever-smaller cylinders on top of each other with texts on the side, starting from the top. (Effectively the same as the example, but rather than starting from the bottom and go up, it would start from the top and go down.) Ideally the size of the last (and the widest) cylinder from 1 would transition smoothly to the top-most cylinder from 2. In other words, I would like to have to have a set of cylinders first expanding as we move down and then narrowing. Thus far I have been tinkering with the funnel function by trying various combinations of positive and negative signs for \xi, \mwid, etc. None of the combinations have worked. Embarrassingly while the example code produces a wonder set of cylinders almost what I wanted, the PGF/TikZ code in it is much too advanced for my understanding. **Edits: 1. adding the final sentence as it was cut off; 2. steps I have attempted at creating what I wanted.

  • ERROR: Missing number, treated as zero
    by RIRM506 on November 3, 2023 at 3:03 am

    I can't find the problem in the code, but it says at the end of that "Missing number, treated as zero" \begin{tikzpicture}[line cap=round,line join=round,>=stealth,x=1.0cm,y=1.0cm] \begin{axis}[ x=1.5cm,y=1.5cm, axis lines=middle, xlabel=$x$, ylabel=$y$, xmin=-0.5, xmax=6.0, ymin=-0.5, ymax=4.5, xticklabels={,,1,,,4}, ytick={\empty},] \clip(-0.5,-0.5) rectangle (6.,4.5); \fill[fill=black,fill opacity=0.20000000298023224] (1.0045836142718776,1.4243770120110515) -- (1.0045836142718776,0.) -- (4,0) -- (3.996318624435588,0.5559251076370629) -- (3.764797284337927,0.5803447447339725) -- (3.5176114060500536,0.609277926604037) -- (3.0369721982680775,0.676251412660451) -- (2.7554549479957773,0.7294953956208646) -- (2.535734167295445,0.7672558117999624) -- (2.309147112198228,0.8185829277750029) -- (2.0550949595134687,0.8866827343500797) -- (1.8010428068287099,0.9697221311676422) -- (1.5401243797470656,1.0769669337835905) -- (1.3135373246498483,1.1965218380095286) -- (1.1487467391245991,1.306084296440851) -- cycle; \draw[line width=1.2,smooth,samples=100,domain=6-6:6.1] plot(\x,{10/(2*(\x)+5*sqrt((\x)))}); \draw [line width=1.2pt] (1.0045836142718776,1.4243770120110515)-- (1.0045836142718776,0); \draw [line width=1.2pt] (3.996318624435216,0.5559251076932408)-- (4.,0.); \draw (-0.4,0.02) node[anchor=north west] {$O$}; \draw (2.2424396505089295,0.6291874906703163) node[anchor=north west] {$\mathbf{R}$}; \end{axis} \end{tikzpicture}

  • How can I remove the Labels of the blue dots on the left plot and change the position of label nr16 in the right plot?
    by dan1365 on March 30, 2023 at 9:46 am

    \documentclass[11pt]{report} \usepackage{pgfplots, pgfplotstable} \pgfplotsset{width=10cm,compat=1.18} \usepackage{graphicx} \usepackage{caption} \usepackage{subcaption} \begin{document} \begin{figure} \centering \begin{subfigure}[tb]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[height=7cm, width=\linewidth, xlabel={}, ylabel={}, ytick={0,500,...,1700}, xtick={0,500,...,1700}, ymin=-170, ymax=1700, xmin=-170, xmax=1700, ymajorgrids, xmajorgrids] \addplot[ scatter/classes={0={blue}, 1={red}}, scatter, mark=*, only marks, scatter src=explicit symbolic, nodes near coords*={\Label}, visualization depends on={value \thisrow{label} \as \Label} %<- added value ] table [meta=class] { x y class label 0.3788 8.1653 0 - 6.3716 4.0196 0 - 0.4225 0.1447 0 - 14.8118 6.6124 0 - 2.7433 2.544 0 - 152.0046 30.6336 1 5 1375 428.5714 1 6 20.51 5.1280 0 - 38.8548 1492.8425 1 8 0.1409 0.000196 0 - }; \end{axis} \end{tikzpicture} \caption{} \label{} \end{subfigure}\hfill \begin{subfigure}[tb]{0.48\linewidth} \begin{tikzpicture} \begin{axis}[height=7cm, width=\linewidth, xlabel={}, ylabel={}, ytick={0,2,...,10}, xtick={0,5,...,20}, ymin=-1.133, ymax=11.333, xmin=-2.266, xmax=22.666, ymajorgrids, xmajorgrids] \addplot[ scatter/classes={0={blue}, 1={red}}, scatter, mark=*, only marks, scatter src=explicit symbolic, nodes near coords*={\Label}, visualization depends on={value \thisrow{label} \as \Label} %<- added value ] table [meta=class] { x y class label 0.3788 8.1653 0 9 6.3716 4.0196 0 10 0.4225 0.1447 0 12 14.8118 6.6124 0 13 2.7433 2.544 0 14 20.51 5.1280 0 15 0.1409 0.000196 0 16 }; \end{axis} \end{tikzpicture} \caption{} \label{} \end{subfigure}\hfill \caption{} \end{figure} \end{document} > Blockquote

  • Ghost shape in TikZ/pgf
    by JeT on October 7, 2021 at 10:09 pm

    My question I can easily draw the normal distribution thanks to this answer by Jake. What about the ghost ? Context This image always breaks the ice when teaching probabilities 🙂 (Not that I care so much about it, but Halloween is getting closer too) I presume it would be possible with Inkscape (but I am not familiar with it). This answer by Paul Gaborit uses the hobby package I tried to adapt (poorly as you'll see, far too manual to be honnest) in my MWE. I'd be happy to see different approaches too (pure tikz, pgfplot, other libraries...). \documentclass[tikz]{standalone} \usetikzlibrary{hobby} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture}[use Hobby shortcut] \draw[ help lines, line width=0.1pt, blue, ] (-20, -20) grid[step={($(5, 5) - (0, 0)$)}] (60, 100); \path (0,0) coordinate (z0) (10,10) coordinate (z1) (20,0) coordinate (z2) (30,10) coordinate (z3) (40,0) coordinate (z4) (50,10) coordinate (z5) (30,90) coordinate (z6) (0,70) coordinate (z7) (0,60) coordinate (z8) ; \draw[closed,black, line width= 3mm] (z0) .. (z1) .. (z2) .. (z3) .. (z4) .. (z5).. (z6).. (z7).. (z8); \end{tikzpicture} \end{document}

  • High entropy alloy in TikZ
    by Janosh on August 28, 2020 at 10:33 am

    I'm trying to reproduce this illustration of a high entropy alloy (HEA) in TikZ: What I have so far looks quite bland because I can't find a way to randomly assign one out of a list of colors. \documentclass[tikz]{standalone} \def\colors{{red,green,blue,yellow}} \begin{document} \begin{tikzpicture}[] \foreach \i in {1,...,12} { \foreach \j in {1,...,6} { \foreach \k in {1,...,4} { \pgfmathparse{rnd} \definecolor{randColor}{rgb}{\pgfmathresult,\pgfmathresult,\pgfmathresult} \shade[ball color=randColor] (\i, {0.5*\j+\k}) circle(0.4); } } } \end{tikzpicture} \end{document} Two questions: How can I assign one of \colors{{red,green,blue,yellow}} either randomly or seemingly randomly based on e.g. Mod(num, base) to each of the balls? I was unable to get array indexing to work: \shade[ball color=\colors[Mod(\i+\j+\k, 4)] and \pgfmathparse{\i+\j+\k} \shade[ball color=\colors[Mod(\pgfmathresult, 4)]] both throw errors. Can the viewing angle be rotated so as to resemble the target image?

  • Remove Zero as Chapter Number in Header Using scrlayer-scrpage
    by Echo on April 9, 2020 at 7:16 pm

    I am currently working on a layout for a document (based on this post and this), using scrbook with scrlayer-scrpage. After a long struggle to get lines with rounded corners in the header and footer, everything works as expected -- except the numbering of the table of contents in the header. For some reason that I do not understand (I am sure because lack of basic knowledge) it gets a chapter number 0 and section number 0.0, instead of an empty field, which is the desired output for unnumbered chapters. When I compile my document with the slightly modified original code for the header no numbers are given for the table of contents. Based on this, my idea was to use \ifnumbered{chapter}{THEN}{ELSE}, either by redefining \chaptermarkformat and \sectionmarkformat (IDEA 1) or by changing the output for \lehead{} (and \rohead{} IDEA 2). What am I missing? Any help is much appreciated. Thank you in advance. Here is the code containing my approaches and the modified original code for the header and footer for camparison: \documentclass[12pt,paper=a4,DIV=calc,parskip=off,numbers=noenddot,chapterprefix=false]{scrbook} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage[ngerman]{babel} \usepackage[T1]{fontenc} \usepackage{calc} \usepackage[dvipsnames]{xcolor} \usepackage[inner=1.5cm,outer=3.0cm,top=1.5cm,bottom=2cm,headheight=8mm,headsep=1cm,footskip=1cm,includeheadfoot]{geometry} % ,showframe \setlength{\marginparwidth}{2.77cm} \setlength{\marginparsep}{.2cm} \usepackage[onehalfspacing]{setspace} % Chapter Title Layout ------------------------------------------------- % BASED ON: https://tex.stackexchange.com/questions/423091/chapter-heading-designs-in-koma-script \usepackage{tikz} \usetikzlibrary{positioning, backgrounds} \usepackage[outline]{contour} \contourlength{1.25pt} \usepackage{tikzpagenodes} \renewcommand\raggedchapter{\raggedright} \setkomafont{chapter}{\Huge} \setkomafont{chapterprefix}{\LARGE} \newkomafont{chapternumber}{\bfseries\fontsize{75pt}{75pt}\selectfont} \tikzset{ headings/base/.style = { outer sep = 0pt, inner sep = 0pt, %draw, rectangle % just for testing purposes }, headings/chapterbackground/.style = { headings/base, % if shades are to be used (gave ugly results for the shading): % shade, % left color = white, % right color = black, % without shades: color = black }, headings/chapapp/.style = { headings/base, text = black, font = \usekomafont{chapterprefix} }, headings/chapternumber/.style= { headings/base, text = black, font = \usekomafont{chapternumber} } } \makeatletter \renewcommand*\chapterlinesformat[3]{% \ifstr{#1}{chapter}{% \begin{tikzpicture}[baseline=(title.base)] \node[headings/base,anchor=center](title){% \parbox[t]{\dimexpr\textwidth\relax} {\parbox[t][\height]{\dimexpr\textwidth\relax}{\raggedchapter{#3}}\strut}% {\raggedchapter{\leavevmode\vphantom{\textbf{Ôp'}}#3}} //orig: {\raggedchapter #3} }; % chapter number \ifstr{#2}{} { % a phantom chapternumber is set to achieve the same vertical spacing for toc and other unnumbered chapters as for numbered chapters \node(chapternumber)[anchor=south west,headings/chapternumber] at([yshift=-14.5pt] title.north east){\leavevmode\vphantom{88}};% \fill[headings/base,anchor=north west,rounded corners=2.5 pt] ([xshift=4 pt]chapternumber.north west) rectangle ([yshift=-7 pt,xshift=.33\marginparwidth+4 pt]chapternumber.north west);% \fill[headings/base,color=black!85,anchor=north west,rounded corners=2.5 pt] ([yshift=-9 pt,xshift=5.5pt]chapternumber.north west) rectangle ([yshift=-16 pt,xshift=.33\marginparwidth+5.5pt]chapternumber.north west);% \fill[headings/base,color=black!70,anchor=north west,rounded corners=2.5 pt] ([yshift=-18 pt,xshift=9pt]chapternumber.north west) rectangle ([yshift=-25 pt,xshift=.33\marginparwidth+9pt]chapternumber.north west);% \fill[headings/base,color=black!50,anchor=north west,rounded corners=2.5 pt] ([yshift=-27 pt,xshift=16.5pt]chapternumber.north west) rectangle ([yshift=-34 pt,xshift=.33\marginparwidth+16.5pt]chapternumber.north west);% \fill[headings/base,color=black!20,anchor=north west,rounded corners=2.5 pt] ([yshift=-36 pt,xshift=30pt]chapternumber.north west) rectangle ([yshift=-43 pt,xshift=.33\marginparwidth+30pt]chapternumber.north west);% \fill[headings/base,color=black!10,anchor=north west,rounded corners=2.5 pt] ([yshift=-45 pt,xshift=52pt]chapternumber.north west) rectangle ([yshift=-52 pt,xshift=.33\marginparwidth+52pt]chapternumber.north west);% } { % number definition for numbered chapters \node(chapternumber)[anchor=south west,headings/chapternumber] at([yshift=-14.5pt] title.north east){#2};% } % decorative element(s) \ifstr{#2}{}{}{ \fill[headings/chapterbackground,anchor=east,rounded corners=1 pt] ([yshift=11.5 pt]title.north east) rectangle ([yshift=13.5 pt,xshift=4.2 cm]title.north);% } % chapter prefix \node(chapapp)[headings/chapapp,anchor=north east] at (chapternumber.north west){\ifstr{#2}{}{\leavevmode\vphantom{\contour{white}\chapapp}}{\contour{white}\chapapp}\strut};% \end{tikzpicture} \par }{% \@hangfrom{#2}{#3}% other section levels using style=chapter }% } \makeatother % Header and Footer Layout -------------------------------- \usepackage[automark]{scrlayer-scrpage} \setkomafont{pageheadfoot}{\footnotesize} \setkomafont{pagehead}{\sffamily\normalsize} \setkomafont{pagenumber}{\sffamily\large} \clearpairofpagestyles \newlength{\vrulewidth} \setlength{\vrulewidth}{1.25 pt} \renewcommand\chaptermark[1]{% \markboth{\ifnumbered{chapter}{#1}{#1}}{\ifnumbered{chapter}{#1}{#1}}% } % IDEA 1: Supposed to remove chapternumber from header in table of contents -- does not % \renewcommand*{\chaptermarkformat}{% % \ifnumbered{chapter}{\chapappifchapterprefix{\ }\thechapter\autodot\enskip}{}% taken from scrguide % } \renewcommand\sectionmark[1]{% \markright{\ifnumbered{section}{#1}{#1}}% } % IDEA 1 (part 2): Supposed to remove sectionumber from header in table of contents -- does not % \renewcommand*{\sectionmarkformat}{% % \ifnumbered{section}{\thesection\autodot\enskip}{}% taken from scrguide % } \lehead{% % \ifnumbered{chapter}{% IDEA 2: Supposed to remove chapternumber from header in table of contents -- does not \begin{tikzpicture}[overlay,remember picture] \fill[headings/base,color=black,anchor=south east,rounded corners=0.5\vrulewidth] ([xshift=-\marginparsep+.5\vrulewidth] current page header area.south west) rectangle ([xshift=-\marginparsep-.5\vrulewidth,yshift=\baselineskip] current page header area.south west); \node[headings/base,anchor=south east] at ([xshift=-2\marginparsep] current page header area.south west){\ifnumbered{chapter}{\leavevmode\vphantom{\headmark\strut}\chaptermarkformat}{\leavevmode\vphantom{\headmark\strut}}}; \node[headings/base,anchor=south west] at (current page header area.south west){\headmark\strut}; \end{tikzpicture} % }% IDEA 2 (part 2) % {% % \begin{tikzpicture}[overlay,remember picture] % \fill[headings/base,color=black,anchor=south east,rounded corners=0.5\vrulewidth] % ([xshift=-\marginparsep+.5\vrulewidth] current page header area.south west) % rectangle % ([xshift=-\marginparsep-.5\vrulewidth,yshift=\baselineskip] current page header area.south west); %% \node[headings/base,anchor=south east] at ([xshift=-2\marginparsep] current page header area.south west){\ifnumbered{chapter}{\leavevmode\vphantom{\headmark\strut}\chaptermarkformat}{\leavevmode\vphantom{\headmark\strut}}}; % \node[headings/base,anchor=south west] at (current page header area.south west){\headmark\strut}; % \end{tikzpicture} % } } \rohead{% (IDEA 2 did not work for \lehead) \begin{tikzpicture}[overlay,remember picture] \fill[headings/base,color=black,anchor=south west,rounded corners=0.5\vrulewidth] ([xshift=\marginparsep-.5\vrulewidth] current page header area.south east) rectangle ([xshift=\marginparsep+.5\vrulewidth,yshift=\baselineskip] current page header area.south east); \node[headings/base,anchor=south west] at ([xshift=2\marginparsep] current page header area.south east){\ifnumbered{section}{\leavevmode\vphantom{\headmark\strut}\sectionmarkformat}{\leavevmode\vphantom{\headmark\strut}}}; \node[headings/base,anchor=south east] at (current page header area.south east){\headmark\strut}; \end{tikzpicture} } \lefoot*{% \begin{tikzpicture}[overlay,remember picture] \fill[headings/base,color=black,anchor=south east,rounded corners=0.5\vrulewidth] ([xshift=-\marginparsep+.5\vrulewidth] current page footer area.south west) rectangle ([xshift=-\marginparsep-.5\vrulewidth,yshift=-3\baselineskip] current page footer area.south west); \node[headings/base,anchor=south east] at ([xshift=-2\marginparsep,yshift=-3\baselineskip] current page footer area.south west){\pagemark\strut}; \end{tikzpicture}% } \rofoot*{% funktioniert ohne * nur auf nicht chapter-Seiten \begin{tikzpicture}[overlay,remember picture] \fill[headings/base,color=black,anchor=south west,rounded corners=0.5\vrulewidth] ([xshift=\marginparsep-.5\vrulewidth] current page footer area.south east) rectangle ([xshift=\marginparsep+.5\vrulewidth,yshift=-3\baselineskip] current page footer area.south east); \node[headings/base,anchor=south west] at ([xshift=2\marginparsep,yshift=-3\baselineskip] current page footer area.south east){\pagemark\strut}; \end{tikzpicture}% } % https://tex.stackexchange.com/questions/272824/pagenumbers-headers-with-vertical-lines-style %% here there are no numbers for the table of contents in the headings -- numbering in TOC as desired % \renewcommand*{\chaptermark}[1]{% % \markboth{% % \makebox[0pt][r]{% % \ifnumbered{chapter}{% % \chaptermarkformat% Kapitelnummer % %\enskip% Abstand -- wird zu groß, wenn nicht auskommentiert % \rule[-\dp\strutbox]{\vrulewidth}{\baselineskip}% Linie -- Offset,Breite,Höhe % \hspace*{\marginparsep}% Abstand % }{}% % }% % #1% Text % }{% % #1%Text % \makebox[0pt][l]{% % \hspace*{\marginparsep}% Abstand % \ifnumbered{chapter}{% % \rule[-\dp\strutbox]{\vrulewidth}{\baselineskip}% Linie -- Offset,Breite,Höhe % \enskip% Abstand % \chaptermarkformat% Kapitelnummer % }{}% % }% % }% % } % \renewcommand*{\sectionmark}[1]{% % \markright{% % #1%Text % \makebox[0pt][l]{% % \ifnumbered{section}{% % \hspace{\marginparsep}% Abstand % \rule[-\dp\strutbox]{\vrulewidth}{\baselineskip}% Linie -- Offset,Breite,Höhe % \enskip% Abstand % \sectionmarkformat% Abschnittsnummer % }{}% % }% % }% % } % \ohead{\headmark} % \rofoot*{% % \makebox[0pt][l]{% % \hspace{\marginparsep}% % \raisebox{0pt}[\ht\strutbox][\dp\strutbox]{% % \rule[-\dp\strutbox]{\vrulewidth}{2\baselineskip}% Linie -- Offset,Breite,Höhe % }% % \enskip % \pagemark % }% % } % \lefoot*{% % \makebox[0pt][r]{% % \pagemark % \enskip % \raisebox{0pt}[\ht\strutbox][\dp\strutbox]{% % \rule[-\dp\strutbox]{\vrulewidth}{2\baselineskip}% Linie -- Offset,Breite,Höhe % }% % \hspace{\marginparsep}% % }% % } \usepackage{blindtext} \usepackage[raiselinks,colorlinks,bookmarks,pageanchor,hyperindex]{hyperref} \hypersetup{linkcolor=RoyalBlue} \begin{document} \markboth{Inhaltsverzeichnis}{Inhaltsverzeichnis} \setcounter{page}{1} \pagenumbering{Roman} \tableofcontents \setcounter{tocdepth}{3} \clearpage \setcounter{page}{1} \pagenumbering{arabic} \Blinddocument \Blinddocument \Blinddocument \Blinddocument \Blinddocument \Blinddocument \Blinddocument \Blinddocument \Blinddocument \appendix \Blinddocument \end{document} Edit: here are some images to visualize the differences: EDIT: I just figured out (here) that the problem is that \ifnumbered{chapter} checks the value of secnumdepth which is not altered in the header, as far as I understood, and a redefinition of chaptermark is needed. My redefinition is obviously not enough for the intended result.

  • How can I draw great circles on a diagram using specific coordinates with arbitrary rotation?
    by Demitri on April 9, 2020 at 6:35 am

    I'm trying to reproduce 3D diagrams like these of quadrilateralized spheres (taken from here) using TikZ: It's important that I use specific celestial coordinates (lat/lon can be substituted without a problem) so that I can draw individual bins as well as label them. More generally, the problem is how to draw arcs of great circles from provided coordinates (all lines of the scheme are great circles). My aim is to do this while working in native coordinates, e.g. "draw an arc from (0°,-45°) to (0°,45°) to (45°,45°) to (45°,0°)". I have found all of the pieces to solve this problem from these sources: Spheres, great circles and parallels by Denis Roegel" - aiming for this look This fantastic StackExchange answer This example The first link is in Metapost but contain the maths, which are used in the second two links. However, the latter two approaches are just different enough that I've not been able to generalize the solution. One uses \tdplotsetmaincoords to set the viewing angle and rotate the coordinate system, while the other uses \begin{scope} to modify the frame. I've tried to reconstruct each plot from basics, but have not been able to sufficiently abstract away the geometry while being able to arbitrarily rotate the sphere and use my "native" coordinates (and keeping the ability to have the "hidden" dashed lines drawn). There are a lot of moving parts! (The visual quality of the examples above are preferred over the above diagrams.) Any help greatly appreciated.

  • Tikz gives Error: Command \@EveryShipout@Hook already defined
    by user27665 on October 26, 2017 at 7:17 pm

    I am trying to use the WACV 2018 conference template. When I add tikz \usepackage{tikz} I get error: ! LaTeX Error: Command \@EveryShipout@Hook already defined. How do I fix this? I couldnt find where its defined

  • rotate node in 3D
    by Fadwa on November 19, 2015 at 6:54 am

    I am trying to draw this 3D shape I draw the 4 arrows and the cylinder, but can't rotate the arrows in 3D to put them on the top. \documentclass{standalone} \usepackage[usenames,dvipsnames]{xcolor} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \usetikzlibrary{shapes.arrows} \begin{document} %,rotate around={30:(0,1,1)} \begin{tikzpicture} \node[cylinder, draw=white,fill=blue, shape aspect=0.7,rotate=90,minimum height=0.7cm, minimum width=2cm] {hh}; \node [fill=red,single arrow, draw=none, rotate=90,minimum height=1cm,minimum width=0.7cm]at(0,0) {}; \node [fill=blue,single arrow, draw=none, rotate=-90,minimum height=1cm,minimum width=0.7cm] at (0,1.5) {}; \node [fill=red,single arrow, draw=none, rotate=-180,minimum height=1cm,minimum width=0.7cm]at(-0.75,0.7) {}; \node [fill=blue,single arrow, draw=none, rotate=-360,minimum height=1cm,minimum width=0.7cm] at (0.75,0.7) {}; \end{tikzpicture} \end{document}

  • PGF: draw longitudinal arcs in 3D axis environment
    by Bloch on February 4, 2015 at 3:54 pm

    I want to draw a sphere similar to the first one here: http://www.texample.net/tikz/examples/map-projections/ But, of course, different. This is what I did so far: The dashed lines are behind the arrows and the solid lines on top to create the illusion of the arrows to be in the sphere. What I did is a bit tricky and probably not the most elegant method. I created a tilted sphere (surface plot) in the background and covered it with a better looking 'ball'. I originally intended the surface plot sphere to be the actual sphere and then decided that it did not look good enough. But I kept it in the background because I needed the axis environment as I did not manage to do it without the axis cs. The latitude lines are basically 360° arcs originating from the (axis cs: 1,0,0) point (arc (0:360:1)). It turned out that arc interpreted the angle as the polar angle (the angle in the x-y-plane), which made it easy. But it seems to make it impossible for longitude lines. Is there something like an arc3D knowing an azimuthal angle in addition to the polar angle? Or could I redraw the latitude lines and rotate them by 90 degrees? Does anyone know another solution? My attempts to do it without the axis environment also failed. Actually I am not unhappy with my axis solution, as it makes it easier to plot the arrows in the right direction (what it will be all about in the end). I hope I could make it clear what my problem is and hope there is someone coming up with an easy arc3D solution. 😉 My code is: \documentclass[tikz]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.9} \usetikzlibrary{arrows.meta} \tikzset{>=Latex} \begin{document} \begin{tikzpicture} \def\tilt{45} \def\azimuth{30} \begin{axis}[% axis equal, width=14cm, height=14cm, hide axis, enlargelimits=0.3, view/h=\tilt, view/v=\azimuth, scale uniformly strategy=units only, colormap={bluewhite}{color=(blue) color=(white)}, ] \coordinate (X) at (axis cs: 1,0,0); \coordinate (-X) at (axis cs: -1,0,0); \coordinate (Y) at (axis cs: 0,1,0); \coordinate (-Y) at (axis cs: 0,-1,0); \coordinate (Z) at (axis cs: 0,0,1); \coordinate (-Z) at (axis cs: 0,0,-1); Kugel \addplot3[ surf, shader= interp, opacity = 1, samples=2, domain=-1:1,y domain=0:2*pi, z buffer=sort ] ({sqrt(1-x^2) * cos(deg(y))}, {sqrt( 1-x^2 ) * sin(deg(y))}, x); \filldraw[ball color=white] (axis cs: 0,0,0) circle (2.5cm); %dashed lines %Breitengrade \pgfplotsinvokeforeach {-80,-60,...,80}{ \pgfplotsextra{ \pgfmathsetmacro\sinVis{sin(#1)/cos(#1)*sin(\azimuth)/cos(\azimuth)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \coordinate (X) at (axis cs: {cos(#1)},0,{sin(#1)}); \draw [gray,dashed] (X) arc (0:360:{100*cos(#1)}); } } %Achsen \draw [-{>[scale=2]},gray] (axis cs: -1,0,0) -- (axis cs: 1.5,0,0) node [above] {$\sigma_x$}; %x-Achse \draw [-{>[scale=2]},gray] (axis cs: 0,-1,0) -- (axis cs: 0,1.5,0) node [above] {$\sigma_y$}; %y-Achse \draw [-{>[scale=2]},gray] (axis cs: 0,0,-1) node [below]{$\sigma_-$} -- (axis cs: 0,0,1.3) node [above] {$\sigma_+$}; %z-Achse \draw [-{>[scale=1]},cyan,line width = 3pt] (axis cs: 0,0,0) -- (axis cs: 0,0,1.1); \draw [-{>[scale=1]},blue,line width = 3pt] (axis cs: 0,0,0) -- (axis cs: 1,0,0); %Arcs \pgfplotsinvokeforeach {-80,-60,...,80}{ \pgfplotsextra{ \pgfmathsetmacro\sinVis{sin(#1)/cos(#1)*sin(\azimuth)/cos(\azimuth)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \coordinate (X) at (axis cs: {cos(#1)},0,{sin(#1)}); \draw [gray] (X) arc (0:\tilt+\angVis:{100*cos(#1)}) (X) arc (0:-180+\tilt-\angVis:{100*cos(#1)}); } } \end{axis} \end{tikzpicture} \end{document}

  • Parabolic Moebius map on sphere using tikz
    by sheik yerbouti II on September 2, 2014 at 6:06 pm

    There is a discussion here about coding the elliptic Moebius map. I however am interested in how I might do the parabolic one. case [d] The arrow heads are not an issue, but how do I get the lines on the surface of the sphere? Most (all?) tutorials only focus on lines of latitude and longitude)

  • Is there a way to show the version of a document as seen by a colour blind reader?
    by alexwlchan on July 5, 2013 at 2:25 pm

    I’m creating a number of coloured grids with TikZ, which look something like this: This exercise is designed to demonstrate reflections and rotational symmetry. It’s important that the individual colours be distinguishable, and a problem in the past has been colour blindness. Readers who are colour blind can’t distinguish the individual colours, which makes it harder to see the symmetries. I’m using the tool Colour Oracle to test the colours against deuteranopia (green deficiency), protanopia (red deficiency) and tritanopia (blue deficiency), but I’d like to be able to output a PDF that retains these filters, without recalculating every colour by hand. Is there a package that I can use at compile time, or a PDF tool that allows me to simulate colour blindness? As a bonus, the ability to simulate the desaturation that comes from using a projector in a lit room would also be useful. (If anybody is interested in the exercise the original version is a problem on the NRICH website. I’m updating it as part of my summer work.)

  • How to plot functions like ‎‎‎‎‎x=f(y)‎‎ using TikZ?
    by Sisabe on March 27, 2013 at 3:48 pm

    To plot functions in the form of y=f(x), we simply write‎ ‎\draw ‎[‎smooth,‎samples=100‎,domain=0:‎‎2‎‎] ‎plot(\x,‎‎‎‎‎‎‎‎{(\x)...‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎});‎‎ But how about functions like x=f(y)? How to plot them? How to specify their domains ‎in terms of "y"‎? \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw [smooth,samples=100,domain=0:2] plot(???); \end{tikzpicture} \end{document}

  • How to make beamer overlays with Tikz node
    by Peter Smit on November 29, 2010 at 7:23 am

    I have a diagram of 4 nodes in my beamer slide. \begin{figure}[h] \begin{centering} \begin{tikzpicture}[system/.style={draw,rectangle,rounded corners=3,minimum width=2cm,text width=1.8cm,text centered}] \node [system] (fe) {Feature Extraction}; \node [system] (am) [right=of fe] {Acoustic Model}; \node [system] (lm) [right=of am] {Language Model}; \node [system] (d) [below=of lm] {Decoder}; \draw[->] (fe) |- (am); \draw[->] (am) |- (d); \draw[->] (lm) -- (d.north); \end{tikzpicture} \end{centering} \end{figure} How can I in a second slide "highlight" one of the nodes, like I can do with <alert@n> for a item in a list? With highlighting I mean for example giving a color and thickening the lines.