• 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 Med Elhadi Kh 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} \usepackage{mathspec} \usepackage[loadonly]{enumitem} \usetikzlibrary{arrows,shapes,calc} \usepackage{polyglossia} \setmainlanguage[numerals=maghrib]{arabic} \setotherlanguage{french} \newfontfamily\arabicfont[Script=Arabic,Scale=1.2]{Amiri} \newfontfamily\fontb[Script=Arabic,Scale=1.4]{Aljazeera.ttf} \newfontfamily\fonta[Script=Arabic,Scale=1.2]{Al Qalam Quran Majeed Web.ttf} \newfontfamily\frenchfont{Times New Roman} \colorlet{col1}{blue} \colorlet{col2}{col1!50} \pagestyle{empty} \parindent=0mm \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}} \renewcommand{\labelenumi}{ \begin{tikzpicture}[baseline=(1.base)] \node[circle,fill=col1,text=white,font=\bfseries\small,minimum size=4mm,inner sep=1pt] (1) {}; \node[text=white,font=\bfseries\small] at (1) {\arabic{enumi}}; \end{tikzpicture} } \parindent=0mm \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); }]\footnotesize المستوى: - - - - - \hfill السلسلة رقم 01 \hfill الأستاذ: --- -- - - \end{tcolorbox}% \end{otherlanguage}% \vglue-\baselineskip }; \node[text width=0.75\textwidth,inner sep=0mm] at ($(4)!.5!(3)$){ \begin{otherlanguage}{arabic} \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; }]\small ~ \hfill الصفحة \arabic{page} من \pageref{LastPage} \hfill ~ \end{tcolorbox}% \end{otherlanguage}% \vglue-\baselineskip }; \end{tikzpicture} } \begin{document} \begin{center} \begin{tcolorbox}[enhanced,interior style={fill stretch image=blueshade.png,fill image opacity=.5},drop fuzzy shadow southwest=col1,colframe=green,right=0mm,left=0mm,width=\dimexpr\textwidth-6mm] \begin{center}\LARGE\fonta ........................... \end{center} \end{tcolorbox} \end{center} \columnseprule=1pt \columnsep=2mm \begin{multicols*}{2} hello \end{multicols*} \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!

  • 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!

  • Using Beamer colours in \addplot command
    by user446112 on July 29, 2026 at 5:59 pm

    How can I use a Beamer colour (e.g., frametitle.fg) in command \addplot of pgfplots? I tried \addplot[frametitle.fg] but I get error. With thanks.

  • Necessarily high-sampled curve in plain TikZ
    by Jasper on July 28, 2026 at 6:34 am

    I was making a rational double pendulum in Asymptote: // a rational double pendulum import graph; unitsize(3cm); pair truncated_pi(real t) { real t1 = 3.14 * t; return ( cos(t) + cos(t1), sin(t) + sin(t1) ); } path f = graph(truncated_pi, 0, 314, n=10000); draw(f); I wanted to make it in TikZ, but I am running into the issue of needing a number of samples which is beyond the limit imposed by pgfmath. As some of you may be familiar with, I am very fond of plain TikZ. I would like to see if there are ways to achieve this which are not overly ad hoc. For example, one strategy would be to break the domain into separate regions. How would one draw something like this in the spirit of plain TikZ? \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture} \draw[ domain=0:314, samples=10000, trig format=rad, declare function={ t1(\x) = 3.14 * \x; x(\x) = cos(\x) + cos(t1(\x)); y(\x) = sin(\x) + sin(t1(\x)); } ] plot ({x(\x)},{y(\x)}); \end{tikzpicture} \end{document}

  • Draw custom listings caption with tikz over the background
    by umarcor on July 27, 2026 at 3:21 pm

    I'm trying to customise listings captions using tikz, but the background of the code listing is drawn afterwards, covering the tikz caption. How can I ensure the caption to be drawn after/over the code? This is what I want to achieve: The Minimal Working Example (MWE) below shows where I got so far. In the orange examples (adding 4ex before and -5ex after) the tikz picture is properly aligned with the frame/background of the code; however, it's drawn below. Moreover, the vertical space between the previous text and the listing is the same in the cyan and red examples, but it's slightly increased in the orange examples, which I don't understand. On the other hand, the magenta examples use just -1ex before (no forced vertical spacing after) and are properly aligned with the frame/background of the code; but they require several \noparskip to avoid excessive vertical space from the previous text/title, which I neither understand. \documentclass[twoside,openright,11pt]{report} \usepackage[a4paper,margin=2cm]{geometry} \usepackage{filecontents} \edef\restoreparindent{\parindent=\the\parindent\relax} \RequirePackage{parskip} \restoreparindent \newcommand*{\noparskip}{\par\vspace{-\parskip}} \usepackage{fontawesome} \usepackage[dvipsnames,table]{xcolor} \usepackage{tikzpagenodes} % Loads tikz \usetikzlibrary{calc} \usepackage{caption} \usepackage{listings} \lstset{ language=C, basicstyle=\ttfamily, backgroundcolor=\color{gray!5}, frame=single, framerule=0pt, framesep=1ex, xleftmargin=1ex, xrightmargin=1ex, } \captionsetup[lstlisting]{ font={footnotesize,bf}, justification=raggedleft, singlelinecheck=false } \newcommand*\lstc[1]{\noparskip\lstinputlisting[firstline=5, caption = \faFileCodeO~\lstname]{#1}} \DeclareCaptionFormat{rulebox}{% \parbox{\linewidth}{% \makebox[\linewidth]{% \leaders\hrule height 0.5pt\hfill~#1#2#3% }% }% } \DeclareCaptionFormat{tikzrule}{% \begin{tikzpicture}[remember picture, overlay] \node[blue, anchor=east] (P) {#1#2#3}; \draw[blue] (current page text area.west|-0,0) -- (P); \end{tikzpicture} } \DeclareCaptionFormat{tikzrulebox}{% \begin{tikzpicture}[remember picture, overlay] \node[green, draw, anchor=north east] (P) {#1#2#3}; \draw[green] (current page text area.west|-0,0) -- (P.north west); \end{tikzpicture}% } \DeclareCaptionFormat{tikzruleboxpoff}{% \vspace*{4ex} \begin{tikzpicture}[remember picture, overlay] \node[cyan, draw, anchor=north east] (P) {#1#2#3}; \draw[cyan] (current page text area.west|-0,0) -- (P.north west); \end{tikzpicture}% } \DeclareCaptionFormat{tikzruleboxpoffn}{% \vspace*{4ex} \begin{tikzpicture}[remember picture, overlay] \node[red, draw, anchor=north east] (P) {#1#2#3}; \draw[red] (current page text area.west|-0,0) -- (P.north west); \end{tikzpicture}% \vspace*{-4ex} } \DeclareCaptionFormat{tikzruleboxpoffnd}{% \vspace*{4ex} \begin{tikzpicture}[remember picture, overlay] \node[orange, draw, anchor=north east] (P) {#1#2#3}; \draw[orange] (current page text area.west|-0,0) -- (P.north west); \end{tikzpicture}% \vspace*{-5ex} } \DeclareCaptionFormat{tikzruleboxnoff}{% \vspace{-1ex} \begin{tikzpicture}[remember picture, overlay] \node[magenta, draw, anchor=north east] (P) {#1#2#3}; \draw[magenta] (current page text area.west|-0,0) -- (P.north west); \end{tikzpicture}% } \begin{filecontents}{main.c} #include <stdio.h> #include <stdlib.h> int main () { printf("Hello!\n"); return 0; } \end{filecontents} \begin{document} \hrule \section*{Section title} \hrule \captionsetup[lstlisting]{format=rulebox} \lstc{main.c} \vspace*{5ex} \captionsetup[lstlisting]{format=tikzrule} \hrule TikZ Rule \hrule \lstc{main.c} \vspace*{5ex} \captionsetup[lstlisting]{format=tikzrulebox} \hrule TikZ Rule Box \hrule \lstc{main.c} \vspace*{5ex} \captionsetup[lstlisting]{format=tikzruleboxpoff} \hrule 4ex TikZ Rule Box \hrule \lstc{main.c} \vspace*{5ex} \captionsetup[lstlisting]{format=tikzruleboxpoffn} \hrule 4ex TikZ Rule Box -4ex (with rule) \hrule \lstc{main.c} \hrule 4ex TikZ Rule Box -4ex (no rule) \noparskip% \lstc{main.c} \newpage \captionsetup[lstlisting]{format=tikzruleboxpoffnd} \hrule 4ex TikZ Rule Box -5ex (with rule) \hrule \lstc{main.c} \hrule 4ex TikZ Rule Box -5ex (no rule) \noparskip% \lstc{main.c} \vspace*{5ex} \captionsetup[lstlisting]{format=tikzruleboxnoff} \hrule TikZ Rule Box N off (with hrule) \hrule \noparskip% \lstc{main.c} \hrule TikZ Rule Box N off (no hrule) \noparskip% \noparskip% \lstc{main.c} \end{document} EDIT Applying the solution proposed by @kabenyuk below, it works nicely except if the lstlisting needs to be located at the top of a page. In such case, the caption is put at the top of the current page and the code at the top of the next one. \documentclass{report} \usepackage{filecontents} \usepackage{lipsum} \usepackage{xcolor} \usepackage{tikzpagenodes} % Loads tikz \usetikzlibrary{calc} \usepackage{caption} \usepackage{listings} \lstset{ language=C, backgroundcolor=\color{gray!5}, } \newcommand*\lstc[1]{\lstinputlisting[caption = \lstname]{#1}} %% Deferred drawing of TikZ captions \makeatletter % A number unique to each TikZ caption. \newcount\lstcaption@id % Store the caption contents and mark its position. \newcommand*{\lstcaption@store}[1]{% \global\advance\lstcaption@id\@ne \edef\lstcaption@thisid{\the\lstcaption@id}% % Create a separate box for each caption, since one page may contain several listings. \expandafter\newsavebox \csname lstcaption@box@\lstcaption@thisid\endcsname \global\setbox \csname lstcaption@box@\lstcaption@thisid\endcsname = \hbox{#1}% % Only the coordinate is placed here. The actual drawing will be produced later. \begin{tikzpicture}[remember picture,overlay] \coordinate (lstcaption@pos@\lstcaption@thisid) at (0,0); \end{tikzpicture}% } \newcommand*{\lstcaption@draw}[1]{% \begin{tikzpicture}[remember picture,overlay] \node[draw, opacity=.75, anchor=north east] (P) at (lstcaption@pos@#1) {\copy\csname lstcaption@box@#1\endcsname}; \draw[opacity=.75] (current page text area.west|-P.north west) -- (P.north west); \end{tikzpicture}% } \DeclareCaptionFormat{tikzrulebox}{% % Store a caption and schedule it to be drawn in the foreground layer of the page. \lstcaption@store{#1#2#3}% \edef\lstcaption@tmp{% \noexpand\AddToHookNext{shipout/foreground}{% \noexpand\lstcaption@draw{\lstcaption@thisid}% }% }% \lstcaption@tmp } \makeatother \captionsetup[lstlisting]{ format=tikzrulebox, justification=raggedleft, singlelinecheck=false, aboveskip=-1ex, } \begin{filecontents}{main.c} #include <stdio.h> #include <stdlib.h> int main () { printf("Hello!\n"); return 0; } \end{filecontents} \begin{filecontents}{another.c} #include <stdio.h> int main () { printf("Bye!\n"); } \end{filecontents} \begin{document} \section*{Section title} \lstc{main.c} This is some regular text. \lstc{main.c} \lipsum[1-2] \lipsum[1][1-5] \lstc{another.c} \end{document}

  • Keep track of the number of chapters in each part
    by umarcor on July 26, 2026 at 2:48 pm

    In the following Minimal Working Example (MWE), I'd like to keep track of the totvalue of chapcnt within each part (since chapcnt is set to 0 at the beginning of each part). Currently, \totvalue{chapcnt} returns the number of chapters in the last part (the maximum after it is last reset in the document). \documentclass[twoside]{report} \let\latexthesection\thesection \renewcommand*{\thesection}{\arabic{section}} \usepackage{titlesec} \titleclass{\part}{top} \titleformat{\part}{\Huge\bfseries\color{blue}}{\thepart}{10pt}{} \titleclass{\chapter}{top} \titleformat{\chapter}{\Huge\bfseries\color{green}}{\thechapter}{10pt}{} \usepackage{tikz} \usetikzlibrary{calc} \usepackage{totcount, eso-pic, xifthen} \regtotcounter{partcnt} \newcounter{partcnt} \regtotcounter{chapcnt} \newcounter{chapcnt} \AddToShipoutPictureBG{% \begin{tikzpicture}[overlay] \ifthenelse{\isodd{\value{page}}}% {\def\corner{east}\def\sign{-}}% {\def\corner{west}\def\sign{+}} \pgfmathsetlengthmacro{\parttabheight}{\paperheight/\totvalue{partcnt}} \pgfmathsetlengthmacro{\parttaboffset}{(\thepartcnt-1)*\parttabheight} \fill[blue] ($(current page.north \corner)+(0,-\parttaboffset)$) rectangle ++(\sign.40,-\parttabheight); % FIXME Chapters should be counted within the part, thus keeping one chapter totvalue per part to adjust the chaptabheight in each part. \ifthenelse{\thechapcnt>0} { \pgfmathsetlengthmacro{\chaptabheight}{\parttabheight/\totvalue{chapcnt}} \pgfmathsetlengthmacro{\chaptaboffset}{(\thechapcnt-1)*\chaptabheight} \fill[green] ($(current page.north \corner)+(\sign.20,-\parttaboffset-\chaptaboffset)$)% rectangle ++(\sign.40,-\chaptabheight); }{} \end{tikzpicture} } \newcommand*{\unpart}[1]{ \part*{#1} \stepcounter{partcnt} \setcounter{chapter}{0} \setcounter{chapcnt}{0} \thepartcnt~\thechapcnt } \newcommand*{\unchapter}[1]{ \chapter*{#1} \stepcounter{chapcnt} \thepartcnt~\thechapcnt } \begin{document} \unpart{FirstPart} \unchapter{P1:FirstUNChapter} \section{A Numbered Section} \section{Another Numbered Section} \unchapter{P1:SecondUNChapter} \chapter{P1:ThirdNChapter} \stepcounter{chapcnt} \thepartcnt~\thechapcnt \unchapter{P1:LastUNChapter} \unpart{SecondPart} \unchapter{P2:FirstUNChapter} \unchapter{P2:SecondUNChapter} \unchapter{P2:ThirdUNChapter} \end{document} In the fourth page below the green rectangle is drawn outside of the blue rectangle because it's using 3 as the total number of chapters. The last part hast 3 chapters but the first one has 4. The chaptabheight of the chapters in the first part should be computed using 4, and the chaptabheight of the chapters in the second part should be computed using 3.

  • Marginnote does not work [duplicate]
    by Rassine Orange on July 26, 2026 at 12:47 pm

    When I try to put a tikzpicture inside a marginnote, I get this error: Equations.tex: error: 132: Argument of \pgfplots@addplotimpl@expression has an extra }. I guess there may be a conflict with another package/options as when I try a MWE with just the marginote, it works, see below. I cannot paste here my whole preambule as it would be too long. What could a possible source of this error? (For context I'm trying to get something similar as can be seen in this discussion. Sadly the code is nowhere to be found in the discussion...) \documentclass[a4paper,11pt]{article} \usepackage[top=2cm,bottom=2cm,right=4cm,left=2cm,marginparsep=0.5cm]{geometry} \usepackage{marginnote} %%%Tikz \usepackage{tikz} \usepackage{pgfplots} \begin{document} A marginote, all good \marginnote{ \begin{tikzpicture} %[x=1cm,y=1cm,auto,rotate=90,transform shape] \begin{axis}[ width=4.5cm, height=3cm, % hauteur xmin=-2, xmax=10, ymin=0, ymax=12, xtick= \empty, ytick= \empty, extra x ticks = {0,2}, extra x tick style={tick style={draw=none}}, extra y ticks = {2, 8,10}, extra tick style={tick style={draw=none}}, axis line style={thick, shorten >=-20pt, shorten <=0pt}, %extra x tick labels={0,0.5,...,10}, %grid style={very thin, dotted, color=gray}, grid=none, % grille verticale et horizontale axis x line=center, axis y line=center, ylabel=$x(t)$, ylabel style={anchor=south,yshift = 0.75cm}, xlabel=$t$, xlabel style={anchor=west,xshift = 0.75cm}, axis line style={>=stealth,->}, ] \addplot+[domain=0:10,color=cyan, thick, smooth,samples=400,mark=none] (\x,{4/(1+5^(-2*\x))}); \addplot+[only marks,mark = *, cyan, mark options={fill=white} ] coordinates { (2,5) (0,4)}; \draw [dashed, cyan] (axis cs:{2,0}) -- (axis cs:{2,5}) -- (axis cs:{0,5}); \draw [dashed, orange] (axis cs:{0,10}) -- (axis cs:{10,10}); \end{axis} \end{tikzpicture}} But does not work \end{document} Edit: The solution was here, the key was to use \shorthandoff. I'm not sure why and what this command does though, so the solution may not be robust.

  • Use inner and outer margins implicitly in tikz when defining a custom section titleformat for a twoside report
    by umarcor on July 26, 2026 at 12:29 pm

    In the following Minimal Working Example (MWE), the section and subsection title formats are modified using titlesec's titleformat along with tikz. In order to handle odd and even pages, command sectitleformat receives arguments #6 and #7, which are {\innermargin}{\outermargin} for odd pages and {\outermargin}{\innermargin} for even pages. Is it possible to avoid defining and using \innermargin and \outermargin, and instead know/compute those margins using tikz's calc/positioning without explicitly passing those two arguments to sectitleformat? So, instead of using sectitleformat four times, I'd like to use it twice only (\sectitleformat[]... and \sectitleformat[numberless]...). \documentclass[twoside,openright,11pt]{report} \usepackage{geometry} \geometry{ showframe, a4paper, hmargin=18mm, bindingoffset=5mm, } \def\innermargin{\dimexpr\oddsidemargin+1in} \def\outermargin{\dimexpr\evensidemargin+1in\relax} \usepackage{MnSymbol} \usepackage{tikz} \usetikzlibrary{calc} \usepackage[explicit]{titlesec} \newcommand*\sectitleformat[7][]{ \titleformat{name=#2, page=#1}{\large\bfseries}{}{0pt}{ \begin{tikzpicture}[remember picture, overlay] \draw[draw=blue, thick] ($(current page.west|-0,0)+(#6,0)$) -- ++(#4,0) node [anchor=west] (S) {#3##1}; \draw[blue, thick] (S) -- ($(current page.east|-0,0)+(-#7,0)$); \end{tikzpicture} } } \newcommand*\sectitleformats[4]{ \sectitleformat[odd]{#1}{#2~$\filleddiamond$~}{#3}{#4}{\innermargin}{\outermargin} \sectitleformat[odd, numberless]{#1}{}{#3}{#4}{\innermargin}{\outermargin} \sectitleformat[even]{#1}{#2~$\filleddiamond$~}{#3}{#4}{\outermargin}{\innermargin} \sectitleformat[even, numberless]{#1}{}{#3}{#4}{\outermargin}{\innermargin} } \sectitleformats{\section}{\thesection}{.5cm}{fill} \sectitleformats{\subsection}{\thesubsection}{.75cm}{fill} \begin{document} \section{Numbered sec} \subsection{Numbered subsec} \section*{Numberless sec} \subsection*{Numberless subsec} \newpage \section{Another Numbered sec} \subsection{Another Numbered subsec} \section*{Another Numberless sec} \subsection*{Another Numberless subsec} \end{document}

  • Is there a built-in mechanism in plain TikZ to cache intermediate calculations locally within a plot expression?
    by Jasper on July 25, 2026 at 5:35 am

    Is there a built-in mechanism in plain TikZ to cache intermediate calculations locally within a plot expression? 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? \documentclass{article} \usepackage{tikz} \begin{document} \tikz \draw[domain=0:1] plot ( \x, { (\x-2)^2 % there is an (\x-2) term here - (\x-2)^3 % and it is duplicated here } ) ; \end{document}

  • tkz-euclide: Ignore undrawn points for bounding box
    by Nick A. on July 24, 2026 at 1:34 pm

    I'm using tkz-euclide to draw the following diagram, which is not properly centered: \documentclass{article} \usepackage{tikz} \usepackage{tkz-euclide} \begin{document} \begin{tikzpicture} \tkzDefPoints{0/0/A, 5/0/B} \tkzCalcLength(A,B) \tkzGetLength{dAB} \tkzDefCircle[R](A, 0.4*\dAB) \tkzGetPoint{P1} \tkzInterLC(A,B)(A,P1) \tkzGetPoints{}{C} \tkzDefCircle[R](B, 0.4*\dAB) \tkzGetPoint{P2} \tkzInterLC(A,B)(B,P2) \tkzGetPoints{D}{} \tkzInterCC(A,C)(C,A) \tkzGetPoints{E}{} \tkzInterCC(D,B)(B,D) \tkzGetPoints{F}{} \tkzInterLL(A,E)(B,F) \tkzGetPoint{G} \tkzDrawSegment[thick](A,B) \tkzDrawArc[gray, delta=10](A,C)(E) \tkzDrawArc[gray, delta=10](B,F)(D) \tkzDrawArc[gray, delta=10](C,E)(A) \tkzDrawArc[gray, delta=10](D,B)(F) \tkzDrawSegments[gray, add=0 and .1](A,G B,G) \tkzDrawSegments[thick, blue](A,G B,G) \tkzLabelPoint[below left](A){$A$} \tkzLabelPoint[below right](B){$B$} \tkzLabelPoint[below left](C){$C$} \tkzLabelPoint[below right](D){$D$} \tkzLabelPoint[above left](E){$E$} \tkzLabelPoint[above right](F){$F$} \tkzLabelPoint[above](G){$G$} % \tkzDrawPoints(P2) % \draw[red] (current bounding box.south west) rectangle (current bounding box.north east); \end{tikzpicture} \end{document} Uncommenting the code at the bottom shows the issue is with the point P2: It's only used for calculation and not drawn, but the bounding box is drawn to include it anyway, pushing the diagram left. Is there a way to instruct tikz to ignore this point so the diagram is centered appropriately? Is there a better way to use tkz-euclide to avoid this issue?

  • Adjusting TikZ code example to create clock faces for modular arithmetic graphics
    by Bryan-StackExchange on July 18, 2026 at 4:30 pm

    The following Stack Exchange answers describe two sort of clock faces which are very close to what I need : Chords between nodes on a clock-like diagram using TikZ As seen in the two examples, I would like to : keep the digits on exterior of circle control whether to display the arrows or lines - or, especially, not display them. I have been able to adjust the code of the two answers (details below) in order to : increase the divisions e.g. from 12 to 98 (but see below) obtain any single face and print it using most of size 8.5 x 11 paper I still would like : display only certain values around perimeter - e.g. 12, 3, 6, 9 as might be seen on a normal clock increase the total to 98 but ideally any value. The purpose is generally for looking at symmetry in modular arithmetic. LaTeX seems ideally suited for this vs. e.g. Gnuplot. omit the lines between "nodes" (or markings) potentially create hash marks on the circle at any increment I do not understand many parts of the two code examples, and I believe this is necessary to adjust the examples to my requirements. e.g. the function of modtweleve and TikZMGClockMath. I am using https://tikz.dev/ as a reference - so I suspect I am overlooking a number of resources. The small adjustments to the two answers in the link are IMHO trivial, and I do not think they need to be reproduced here unless requested. some details : in the accepted answer by user Jake, in \newcommand replace 12 with e.g. 50. However, this approach runs into memory problems as the value increases. adjust stepsize in {1,...,12} to e.g. stepsize in {5} gives the fifth clock face only. This is good. in the answer by user percusse I adjusted 12 to 13 and used a single \begin{scope} to control how many pictures are displayed. The resultant image(s) are closest to what I need ; however, I do not understand how the macro is working - e.g. the \modtwelve part. However, the value can be increased to 98 without any memory problems, and create a nice image. In fact, my exact goal is met by adjusting \TikZMGClockMath{3}{28} - giving a 7-fold pattern. Specifically, the drawing would be perfect if the integers between e.g. 0 and 28 were omitted. in that answer, I commented out line 19-29 - from \draw and the first } that appears - to 'omit' the lines (vectors). This seems good. UPDATE: I added hashmarks with this code: \foreach \angle / \label in {90/0, 38.6/14, -12.8/28, -64.2/42, -115.6/56, -167/70, -218.4/84} ... which is good to show 7-fold symmetry, but they are not on the perimeter. The \draw commands adjust the position of a node or line width by the \angle. This is easy to adjust. See https://tikz.dev/pgffor UPDATE I found an inelegant way to add hashmarks - right after the above code, put this in: \draw[line width=0.5pt] (\angle:8.0cm) -- (\angle:8.5cm); } \foreach \angle in {86.3265, 86.3265, 82.6531, [.. skipping...] -258.98, -262.653, -266.327} the values are pre-calculated using awk. It would be nice to reduce that into a \foreach, multiplying the value of the example (360/98). Then, (360/98) could be any division of the circle. I tried asking on the original post, but I do not have the requisite reputation. If there is a better approach, I'd be glad to change this question. output of pdflatex --version from this Ubuntu 24.04.4 system : pdfTeX 3.141592653-2.6-1.40.25 (TeX Live 2023/Debian) [trimmed] ... I cannot recall how it was installed - by apt or something else. Anyhow, it seems to work OK.

  • An original cover of my book for a broken clock
    by Sebastiano on July 17, 2026 at 8:21 pm

    I have tried to create a cover for my book that is beautiful and visually appealing. Since the book deals with topics such as relativity, clocks, four-vectors, spacetime, the calculus of variations, and many other fascinating ideas, I imagined clocks being sucked into an unknown spacetime and deformed in the style of Salvador Dalí. The clocks become distorted until they break apart into many fragments, including the smallest and most symbolic components, such as the central pin and the internal spring. Question: How can you improve the broken clock that loses pieces to make it look more beautiful? \documentclass[12pt,a4paper]{book} \usepackage[T1]{fontenc} \usepackage{amsmath,amsfonts,amssymb} \usepackage{tikz} \usetikzlibrary{calc} \usepackage{geometry} \begin{document} \pagestyle{empty} \begin{tikzpicture}[remember picture, overlay] \coordinate (Centro) at (current page.center); \coordinate (TopRight) at (current page.north east); \coordinate (TopLeft) at (current page.north west); \definecolor{bglight}{RGB}{172, 206, 184} \fill[bglight] (current page.south west) rectangle (current page.north east); \definecolor{clockgold}{RGB}{230, 177, 43} \definecolor{clockgreen}{RGB}{166, 209, 108} \definecolor{clockorange}{RGB}{240, 133, 41} \definecolor{clockgrey}{RGB}{140, 155, 145} \definecolor{gridblue}{RGB}{110, 150, 135} \definecolor{authorgreen}{RGB}{18, 92, 79} \node[anchor=north east, align=right, text width=7cm] at ($(TopRight)+(-1.5,-1.5)$) { {\fontfamily{ptm}\selectfont\LARGE\color{authorgreen}\textbf{Name Surname 1}}\\[0.2cm] {\fontfamily{ptm}\selectfont\LARGE\color{authorgreen}\textbf{Name Surname 2}} }; \node[anchor=north west, align=justify, text width=16cm] at ($(TopLeft)+(1.5,-3.5)$) { {\fontfamily{pnc}\selectfont\huge\itshape\color{white}Lezioni di}\\[0.3cm] {\fontfamily{pnc}\fontseries{b}\fontsize{44pt}{46pt}\selectfont\spaceskip=0.5em\color{white} LONGGGGGGGGGGG\\ [.4cm] LONGGGGGGGGGGG} }; \begin{scope}[shift={(Centro)}, scale=1.6] \begin{scope}[gridblue, opacity=0.5, line width=0.8pt] \foreach \k in {-4.5,-3.7,-2.9,-2.1,-1.3,-0.5,0.5,1.3,2.9,3.7,4.5} { \draw[smooth, samples=40] plot[domain=-5.5:4.5] ({ \k * (1 - 0.6 / (1 + 0.2*\k*\k + 0.2*\x*\x)) }, { \x * (1 - 0.6 / (1 + 0.2*\k*\k + 0.2*\x*\x)) }); } \foreach \k in {-5,-4.1,-3.2,-2.3,-1.4,-0.5,0.5,1.4,2.3,3.2,4} { \draw[smooth, samples=40] plot[domain=-4.8:4.8] ({ \x * (1 - 0.6 / (1 + 0.2*\x*\x + 0.2*\k*\k)) }, { \k * (1 - 0.6 / (1 + 0.2*\x*\x + 0.2*\k*\k)) }); } \end{scope} \fill[white, opacity=0.25, rotate around={12:(3.2,-1.5)}] (1.8,-3) rectangle (4,0); \fill[white, opacity=0.25, rotate around={-15:(-3,2)}] (-4.2,0.8) rectangle (-1.8,3.2); \begin{scope}[shift={(-2.8,2)}, rotate=-15, scale=0.95] \draw[white, fill=white, line width=4pt, line join=round] plot[smooth cycle, tension=0.5] coordinates {(-1,1.1) (1,0.9) (0.9,-1) (-1.1,-0.8)}; \draw[gray!60!black, line width=2pt, line join=round] plot[smooth cycle, tension=0.5] coordinates {(-1,1.1) (1,0.9) (0.9,-1) (-1.1,-0.8)}; \fill[clockgold] plot[smooth cycle, tension=0.5] coordinates {(-0.7,0.8) (0.7,0.7) (0.6,-0.7) (-0.7,-0.5)}; \fill[black] (0,0) circle (2.5pt); \draw[black, ultra thick, ->] plot[smooth, tension=1] coordinates{(0,0) (0.05, 0.25) (0.15,0.5)}; \draw[black, ultra thick, ->] plot[smooth, tension=1] coordinates{(0,0) (-0.2, -0.05) (-0.4,-0.1)}; \foreach \a in {0,90,180,270} \draw[white, thick] (\a:0.55) -- (\a:0.7); \end{scope} \begin{scope}[shift={(-2.6,-0.8)}, rotate=22, scale=1.05] \draw[white, fill=white, line width=4pt, line join=round] plot[smooth cycle, tension=0.7] coordinates {(-0.6,1.4) (0.8,0.4) (0.2,-1.5) (-0.9,-0.8)}; \draw[gray!60!black, line width=2.2pt, line join=round] plot[smooth cycle, tension=0.7] coordinates {(-0.6,1.4) (0.8,0.4) (0.2,-1.5) (-0.9,-0.8)}; \fill[clockgreen] plot[smooth cycle, tension=0.7] coordinates {(-0.4,1.1) (0.5,0.2) (0.1,-1.2) (-0.6,-0.6)}; \fill[black] (-0.1,-0.1) circle (2.5pt); \draw[black, ultra thick, ->] plot[smooth, tension=1] coordinates{(-0.1,-0.1) (0, 0.2) (0.15,0.6)}; \draw[black, ultra thick, ->] plot[smooth, tension=1] coordinates{(-0.1,-0.1) (0.05, -0.3) (0.2,-0.5)}; \draw[black!70, thick] (0.1,0.9) -- (0.2,1.1); \draw[black!70, thick] (-0.4,-0.8) -- (-0.5,-1.0); \end{scope} \begin{scope}[shift={(-.5,-3.6)}, rotate=-15, scale=0.9] \draw[white, fill=white, line width=4pt, line join=round] plot[smooth cycle, tension=0.7] coordinates {(-0.7,1.4) (0.8,1.2) (1.1,-2.2) (-0.9,-2.4)}; \draw[gray!60!black, line width=2pt, line join=round] plot[smooth cycle, tension=0.7] coordinates {(-0.7,1.4) (0.8,1.2) (1.1,-2.2) (-0.9,-2.4)}; \fill[clockgrey!70!clockgreen] plot[smooth cycle, tension=0.7] coordinates {(-0.5,1.1) (0.6,1.0) (0.8,-1.9) (-0.6,-2.0)}; \fill[black] (0.05,-0.1) circle (2.5pt); \draw[black, ultra thick, ->] plot[smooth, tension=1.2] coordinates{(0.05,-0.1) (-0.2, 0.4) (0.3,0.9)}; \draw[black, ultra thick, ->] plot[smooth, tension=1.2] coordinates{(0.05,-0.1) (0.4, -0.6) (0.1,-1.5)}; \draw[black!80, thick] (90:0.6) -- (90:0.8); \draw[black!80, thick] (0:0.5) -- (0:0.7); \draw[black!80, thick] (180:0.4) -- (180:0.6); \draw[black!80, thick] (270:0.6) -- (270:1.3); \end{scope} \begin{scope}[shift={(2.5,-3.8)}, rotate=-35, scale=1.1] \draw[white, fill=white, line width=4pt, line join=round] plot[smooth cycle, tension=0.4] coordinates {(-1.3,0.6) (1.3,0.7) (0.9,-0.6) (-1.1,-0.5)}; \draw[clockorange, line width=2.5pt, line join=round] plot[smooth cycle, tension=0.4] coordinates {(-1.3,0.6) (1.3,0.7) (0.9,-0.6) (-1.1,-0.5)}; \fill[black] (0,0) circle (2.5pt); \draw[black, ultra thick, ->] plot[smooth, tension=1] coordinates{(0,0) (0.3, 0.1) (0.7,0.2)}; \draw[black, ultra thick, ->] plot[smooth, tension=1] coordinates{(0,0) (-0.2, -0.05) (-0.5,-0.1)}; \draw[black!70, thick] (1,0.2) -- (1.2,0.2); \draw[black!70, thick] (-0.9,-0.2) -- (-1.1,-0.2); \end{scope} \begin{scope}[shift={(2.5,2.5)}, rotate=15, scale=0.85] \begin{scope}[shift={(-0.3, 0.2)}, rotate=5] \draw[white, fill=white, line width=3pt] (0,0) -- (110:1.2) arc(110:200:1.2) -- cycle; \fill[clockgrey!70!clockgreen] (0,0) -- (110:1.0) arc(110:200:1.0) -- cycle; \draw[black!80, thick] (180:0.7) -- (180:0.9); \draw[black!80, thick] (120:0.7) -- (120:0.9); \end{scope} \begin{scope}[shift={(0.2, 0.4)}, rotate=-8] \draw[white, fill=white, line width=3pt] (0,0) -- (10:1.3) arc(10:85:1.3) -- cycle; \fill[clockgrey!70!clockgreen] (0,0) -- (10:1.1) arc(10:85:1.1) -- cycle; \draw[black!80, thick] (0:0.8) -- (0:1.0); \draw[black!80, thick] (60:0.8) -- (60:1.0); \draw[black, ultra thick] (30:0.2) -- (45:0.7); \end{scope} \begin{scope}[shift={(0.0, -0.4)}, rotate=12] \draw[white, fill=white, line width=3pt] (0,0) -- (220:1.2) arc(220:340:1.2) -- cycle; \fill[clockgrey!70!clockgreen] (0,0) -- (220:1.0) arc(220:340:1.0) -- cycle; \draw[black!80, thick] (270:0.7) -- (270:0.9); \draw[black!80, thick] (300:0.7) -- (300:0.9); \end{scope} \begin{scope}[shift={(-0.8, -0.9)}, rotate=-30] \draw[white, fill=gray!40, line width=1.5pt] (0,0) -- (0.3,0.4) -- (-0.1,0.5) -- cycle; \end{scope} \begin{scope}[shift={(0.9, -0.2)}, rotate=45] \draw[white, fill=white, line width=2pt] (0,0) -- (0.4,0.1) -- (0.2,0.3) -- cycle; \end{scope} \fill[black] (-0.1,0.05) circle (2.5pt); \begin{scope}[shift={(-0.5, 0.8)}, rotate=25] \draw[black, ultra thick, ->] (0,0) -- (-0.4, 0.5); \end{scope} \draw[gray!80!black, thick, smooth] plot[domain=0:540, samples=40] (\x:{\x*0.001 + 0.05}); \end{scope} \begin{scope}[shift={(2.6,-1.4)}, rotate=45, scale=1.2] \draw[clockorange, line width=5pt, line join=round, fill=white, fill opacity=0.1] plot[smooth cycle, tension=0.2] coordinates {(-1.1,0.5) (1.1,0.5) (0.7,-0.5) (-0.7,-0.5)}; \end{scope} \end{scope} \end{tikzpicture} \clearpage \end{document}

  • How to position the node with `TikZ.positioning` relative to specific angle?
    by Explorer on October 31, 2024 at 2:07 am

    Let's consider the relative coordinate assignment from positioning library, with below left, we could assign 45 degree tilted node: \documentclass[tikz,border=8pt]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[ every node/.style={ draw, circle, inner sep=5pt, outer sep=0pt, fill=cyan!20 } ] \node (O) {$1$}; \node (A) [below left=of O] {$2$} edge (O); \node (B) [below left=of A] {$3$} edge (A); \end{tikzpicture} \end{document} But if I want to change the tilted slope, says for example, 60 degree. Let's assume the following syntax: \documentclass[tikz,border=8pt]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[ every node/.style={ draw, circle, inner sep=5pt, outer sep=0pt, fill=cyan!20 } ] \node (O) {$1$}; % \node (A) [below left={60}{of O}] {$2$} edge (O); % \node (B) [below right={60}{of A}] {$3$} edge (A); \node (A) at ({-sqrt(3)},-3) {$2$} edge (O); \node (B) at (0,-6) {$3$} edge (A); \end{tikzpicture} \end{document} I want the syntax(claim that the assuming syntax here was not the must, I just want to show I want an "angle" key to control the tlited slope, any syntax that allow me to specify the angle 60 here is okay!) such as: \node (A) [below left={60}{of O}] {$2$} edge (O); \node (B) [below right={60}{of A}] {$3$} edge (A); to get the node A and B with following: But not with absolute coordinate. Any suggestions?

  • An interesting example of Horizontal and Vertical Lines in TIKZ?
    by Explorer on August 17, 2024 at 5:17 pm

    I get a little confused by the case of the following example. I learn about the meaning of |- and -| in tikz manuals, but the usage like (1,2 -| S) actually raised my curiosity. the code is as below \documentclass[tikz,border=3.14pt]{standalone} \begin{document} \begin{tikzpicture} \draw[help lines] (-2,-2) grid (4,4); \coordinate (S) at (2,2); \draw[red,thick] (0,0) -- (0,0 -| S); \draw[blue,thick] (0,0) -- (0,0 |- S); \end{tikzpicture} \begin{tikzpicture} \draw[help lines] (-2,-2) grid (4,4); \coordinate (S) at (2,3); \draw[red,thick] (0,0) -- (1,0 -| S); \draw[blue,thick] (0,0) -- (-1,-2 |- S); \end{tikzpicture} \begin{tikzpicture} \draw[help lines] (-2,-2) grid (4,4); \coordinate (S) at (2,3); \draw[red,thick] (0,0) -- (1,-| S); \draw[blue,thick] (0,0) -- (-1,|- S); \end{tikzpicture} \end{document} and I then get the result: I couln't make sense the behavior with the following docs clearly, just guess the with |- S represented the y-coordinate of S, while the -| S represented the x-coordinate of S, is there some docs I left out? How can I know what will happen as (x,y -| <point>) or just (x, |- <point>) or even (,y |- <point>) from the docs?Thanks!

  • How to adjust vertical placement of figure before chapter, chapter heading and section heading in scrbook?
    by Damitr on April 24, 2024 at 9:45 am

    I am trying to create equal vertical spacing in a figure placed at top of page before chapter heading, chapter heading and section heading in scrbook. I tried using the inbuilt koma commands but it is not giving the desired results (or I am not using them correctly. How can I do verical adjustments for the chapter and section headings so that they appear more balanced? MWE \documentclass[10pt]{scrbook} \usepackage{geometry} \geometry{paperheight=150mm,paperwidth=150mm, textwidth=75mm, textheight=100mm, top=20mm, bottom=20mm, marginparwidth=38mm, headsep=8mm, left=10mm, right=55mm, marginparsep=7mm, footskip=10mm} \usepackage{tikz} \RedeclareSectionCommand[beforeskip=2.75cm]{chapter} \RedeclareSectionCommand[afterskip=1cm]{chapter} \RedeclareSectionCommand[beforeskip=0.1\baselineskip,afterskip=0.25\baselineskip]{section} \begin{document} \chapter{first lesson} \label{ch-01} \begin{tikzpicture}[remember picture,overlay,shift=(current page.north west)] \begin{scope}[x={(current page.north east)},y={(current page.south west)}] \node [overlay,remember picture] at (0.5,0.2) {\includegraphics[width=1.2\textwidth]{fig-ch-01-head.pdf}}; \end{scope} \end{tikzpicture} \section{first section} \end{document}

  • An easy way to draw a sphere and cube
    by LH8 on August 25, 2023 at 12:03 pm

    I'm using tikz and would like to obtain this picture: My try: \documentclass[a4paper,12pt]{book} \usepackage{tikz} \usepackage{tikz-cd} \usetikzlibrary{arrows,patterns,snakes,fit,shapes.geometric,arrows.meta,decorations.markings,positioning,shapes,backgrounds} \begin{document} \begin{tikzpicture} \pic {cuboid} node[left]{\simeq} (1,0,0) \simeq \draw[dashed] (0,0,0) circle (1); \draw[dashed] (-1,0,0) arc (180:360:1 and 0.6); \draw[dashed] (1,0,0) arc (0:180:1 and 0.6); \caption{Sample} \end{tikzpicture} \end{document}

  • Beamer class: text height too large for height of footline and headline with tikz pictures
    by Daniel Stich on March 9, 2022 at 11:39 pm

    I tried to recreate my university powerpoint template which includes images as headline and footline banner (beamer class, no predefined theme, xelatex). It seemed easier to place image plus text with tikz. When placing text in frames, text starts within the headline and violates the footline (positioning t or b). My MWE draws a box with \textheightto illustrate the problem. I found this code snippet which should somehow increase the height of the footline but it didn't solve the problem. I hope someone can help me out. Thanks! \makeatletter \patchcmd{\beamer@calculateheadfoot}{\advance\footheight by 4pt}{\advance\footheight by 20pt}{}{} \makeatother MWE: \documentclass[ presentation, %handout, 11pt, aspectratio=43, % 4:3, 128mm:96mm table, usepdftitle=false, ]{beamer} % Packages \usepackage{tikz} \usetikzlibrary{arrows, shapes.arrows, arrows.meta, positioning, fit, calc, backgrounds, patterns, 3d} % Lengths \newlength{\myLeftMargin} \newlength{\myLeftMarginText} \newlength{\myRightMargin} \newlength{\myRightMarginText} \setlength{\myLeftMargin}{0.019685\paperwidth} \setlength{\myLeftMarginText}{0.0909\paperwidth} \setlength{\myRightMargin}{\myLeftMargin} \setlength{\myRightMarginText}{\myLeftMarginText} \setbeamersize{text margin left=\myLeftMarginText} \setbeamersize{text margin right=\myRightMarginText} \setbeamersize{sidebar width left=0pt} % Headline \makeatletter \patchcmd{\beamer@calculateheadfoot}{\advance\footheight by 4pt}{\advance\footheight by 20pt}{}{} \makeatother \setbeamertemplate{headline}{% \begin{tikzpicture}[overlay, remember picture] \node[anchor=north west, inner sep=0pt] at ($(current page.north west)+(0,0)$) (nodeHeadlineBar){ \includegraphics[width=\paperwidth, height=0.15\paperheight]{example-image} }; \end{tikzpicture}% } \setbeamertemplate{frametitle}{% \begin{tikzpicture}[overlay, remember picture] \node[anchor=west, inner sep=0pt] at ($(nodeHeadlineBar.west)+(\myLeftMargin,0)$){ \insertframetitle }; \end{tikzpicture}% } \setbeamertemplate{footline}{% \begin{tikzpicture}[overlay, remember picture] \node[anchor=south west, inner sep=0pt] at ($(current page.south west)+(0,0)$) (nodeFootlineBar){ \includegraphics[width=\paperwidth, height=0.05\paperheight]{example-image} }; \node[anchor=east, inner sep=0pt] at ($(nodeFootlineBar.east)+(-\myRightMargin,0)$){ \insertframenumber\,/\,\inserttotalframenumber }; \end{tikzpicture}% } \begin{document} \section{Example 1} \begin{frame}[b]{\secname} \begin{tikzpicture} \draw[red] (0,0) rectangle (\textwidth,\textheight); \draw[red] (0,\textheight) -- (\textwidth,0) (0,0) -- (\textwidth, \textheight); \end{tikzpicture} \end{frame} \section{Example 2} \begin{frame}[t]{\secname} \begin{tikzpicture} \draw[red] (0,0) rectangle (\textwidth,\textheight); \draw[red] (0,\textheight) -- (\textwidth,0) (0,0) -- (\textwidth, \textheight); \end{tikzpicture} \end{frame} \end{document}

  • 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}

  • Double entry table
    by Dunno on May 27, 2021 at 10:23 am

    I would like to make a double entry table in LaTeX. Here is the result that I would like to get: I found a clue here: \documentclass{article} \usepackage{multirow} \begin{document} \begin{center} \begin{tabular}{ c || l | r | c } & \multicolumn{3}{c}{Columns} \\ \hline \hline \multirow{3}{*}{Rows} & A1 & B1 & C1 \\ \cline{2-4} & A222 & B22 & C2 \\ \cline{2-4} & A3 & B333 & C33 \end{tabular} \end{center} \end{document} I managed to get a partial solution: \begin{document} \begin{center} \begin{tabular}{ l || r | c } A1 & B1 & C1 \\ \hline \hline A222 & B22 & C2 \\ \hline A3 & B333 & C33 \end{tabular} \end{center} \end{document} However, it doesn't solve all my problems. Is it possible to get square cells with everything centered in the cell? I found other partial solutions here but I don't know tikz at all. The matrix environment might not suit my needs because I would like to avoid outer borders and I didn't find any solution with double lines separing row's titles from the inner cells.

  • 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?

  • Code highlighting drawn under tcolorbox and not displayed
    by Zoefschildpad on March 10, 2020 at 10:07 am

    I am looking to add highlighting to listings. I have tried to adept the techniques given by https://tex.stackexchange.com/users/23765/siracusa in the question Highlight text in code listing while also keeping syntax highlighting However I have run into a problem, which is demonstrated in the example below. I want my listing to be inside a tcolorbox. When it isn't in a tcolorbox, the highlighting works as expected. When it is inside the box, the highlighting is rendered properly and in the right place, but it isn't displayed because the tcolorbox seems to be drawn on top of it. Is there a way to draw the highlighting on top of the box (but still under the text) instead? I would really like to keep the core of the highlighting solution, because it plays really nicely with the listings package. Also note that any solution that involves manually adjustments to individual codeblocks is not an option. Their contents are generated by another program, and there are thousands. \LoadClass[10pt]{book} \RequirePackage{fontspec} \RequirePackage{listings} \RequirePackage{xcolor} \RequirePackage{atbegshi} \RequirePackage{ifthen} \RequirePackage{tikz} \usetikzlibrary{calc} \usetikzlibrary{fit} \RequirePackage[breakable]{tcolorbox} % HIGHLIGHTING \makeatletter \newcommand\if@empty[1]{% \if\relax\detokenize{#1}\relax \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi } \newcommand\ifthen[2]{\ifthenelse{#1}{#2}{}} \newcommand\ifelse[2]{\ifthenelse{#1}{}{#2}} % Is highlighting currently active in the listings environment? \newif\ifhl@active % Material executed at each page shipout \newtoks\hl@shipout % Extra styling parameters for the currently active highlight \newtoks\hl@parameters % Inline highlight style. This does not break across line ends \newcommand\hl[2][]{\begingroup\hlstyle@start{#1}#2\endgroup} % The highlight style for listings environments \newcommand\hlstyle[1][]{\hlstyle@start{#1}} \newcommand\hlstyle@start[1]{% \global\hl@activetrue \aftergroup\hlstyle@end \write\@auxout{\noexpand\hl@setparameters{#1}}% \hl@mark{S}% } \newcommand\hlstyle@end{% \hl@mark{E}% \global\hl@activefalse } % Sets the current highlight parameters \newcommand\hl@setparameters[1]{% \global\hl@parameters={#1}% } % Writes a new node marker with the current position and page number to the .aux file \newcommand\hl@mark[1]{% \ensuremath{\vcenter{\hbox{\pdfsavepos}}}% \write\@auxout{\noexpand\hl@processmark{#1}{\the\pdflastxpos}{\the\pdflastypos}{\arabic{page}}}% } % Writes the current page origin to the .aux file, and issues the current \hl@shipout material % to be processed \AtBeginShipout{\AtBeginShipoutUpperLeft{% \pdfsavepos \write\@auxout{\noexpand\hl@processmark{Z}{\the\pdflastxpos}{\the\pdflastypos}{\arabic{page}}}% \hl@doshipout }} % Maintains the current first and last node positions, checks whether a node marker should be used % for the current highlighting segment, and issues a \hl@draw call if necessary. % #1 is either 'S' (start node), 'M' (intermediate node), 'E' (end node), or 'Z' (page origin) % #2/#3 are the x/y-coordinates, #4 is the page number \newcommand\hl@processmark[4]{% \if#1S% \xdef\hl@firstx{#2}% \xdef\hl@firsty{#3}% \xdef\hl@firstp{#4}% \else\if#1M% \ifthenelse{\hl@firsty=#3}{% % Still on same line \xdef\hl@lastx{#2}% \xdef\hl@lasty{#3}% }{% \ifelse{\hl@firstx=\hl@lastx \and \hl@firsty=\hl@lasty}{% % Last highlight part is not empty \expandafter\hl@draw\expandafter{\the\hl@parameters}% }% \xdef\hl@firstx{#2}% \xdef\hl@firsty{#3}% \xdef\hl@firstp{#4}% }% \else\if#1E% \ifthen{\hl@firsty=#3}{% % Still on same line \xdef\hl@lastx{#2}% \xdef\hl@lasty{#3}% \ifelse{\hl@firstx=#2}{% % Last highlight part is not empty \expandafter\hl@draw\expandafter{\the\hl@parameters}% }% }% \else\if#1Z% \xdef\hl@zerox{#2}% \xdef\hl@zeroy{#3}% \fi\fi\fi\fi } % Add a new highlight segment to \hl@shipout to be processed on every shipout. % #1 is the styling command used to draw the segment within a properly positioned \tikz call. % If #1 is empty, \hldefaultstyle is used as a default. Every styling command can take % arbitrary parameters, only the last four are mandatory (x_first, y_first, x_last, y_last) \newcommand\hl@draw[1]{% \edef\@temp{{\noexpand\tikz [ overlay, shift = {(-\hl@zerox sp, -\hl@zeroy sp)} ] {\if@empty{#1}{\noexpand\hldefaultstyle}{\unexpanded{#1}}% {\hl@firstx sp}{\hl@firsty sp}{\hl@lastx sp}{\hl@lasty sp}}}% {\hl@firstp}% }% \expandafter\global\expandafter\addto@hook\expandafter\hl@shipout\expandafter{\@temp}% } % Processes the current \hl@shipout material. The material is a sequence of % {TikZ commands}{page number} pairs \def\hl@doshipout{% \expandafter\hl@doshipout@\the\hl@shipout{}{}\@end } \def\hl@doshipout@#1#2#3\@end{% \if@empty{#2}{}{% \ifthen{\arabic{page}=#2}{#1}% \hl@doshipout@#3\@end }% } % Hook into listings' discretionary breaks \let\orig@lst@discretionary=\lst@discretionary \gdef\lst@discretionary{% \ifhl@active \hl@mark{M}% \fi \orig@lst@discretionary \ifhl@active \hl@mark{M}% \fi } % Styling command for a simple marker highlights \newcommand\hlmarkerstyle[5][yellow]{% \draw [ line width = \baselineskip, #1 ] (#2, #3) -- (#4, #5); } % Default styling command \let\hldefaultstyle=\hlmarkerstyle \makeatother \newcommand\delimstyleB{\hlstyle} %ENDHIGHLIGHTING %% Define custom verbatim as listing allowing background color and mark notation \let\verbatim\someundefinedcommand \lstnewenvironment{CustomVerbatim}[1][name=main] { \lstset{ basicstyle=\fontsize{8}{8}\ttfamily, moredelim=**[is][\delimstyleB]{`}{`}, aboveskip=3mm, breaklines=true, breakatwhitespace=false, keepspaces=true, extendedchars=true, xleftmargin=8pt, xrightmargin=8pt, framextopmargin=3pt, framexbottommargin=3pt, frame=tb, framerule=0pt, escapeinside={¬}{¬}, postbreak=\mbox{\textcolor{blue}{$\hookrightarrow$}\space}, #1 } } {} \newtcolorbox{codebox}[1][] { #1, breakable, size=fbox, arc=0mm, colback=red, colframe=red, } \begin{document} \begin{codebox}\begin{CustomVerbatim}% The text of this `codeblock should be partially highlighted. However, the red box is blocking the highlighting.` \end{CustomVerbatim}\end{codebox} \begin{CustomVerbatim}% The text of `this codeblock is properly partially highlighted, even across multiple lines because it` isn't in a tcolorbox \end{CustomVerbatim} \end{document}

  • TikZ Tree Structure and Genealogytree (or alternatives)
    by Gregory Gelfond on November 21, 2019 at 7:04 pm

    I'm attempting to draw the following "idea genealogy" using TikZ for use in a presentation: and based off a prior answer, I have the following solution. \documentclass[10pt]{standalone} \usepackage[sfdefault]{FiraSans} \usepackage[T1]{fontenc} \renewcommand*\oldstylenums[1]{{\firaoldstyle #1}} \usepackage{tikz} \begin{document} \begin{tikzpicture}[scale=0.50,node distance=20mm,every node/.style={rectangle,minimum height=10mm,text width=17mm,align=center,rounded corners=1mm,draw=black,fill={rgb:red,1;green,2;blue,5},fill opacity=0.2,text opacity=1}] \node at (0,0) (ko) {Kowalski}; \node[above of=ko,node distance=40mm] (le) {Leibniz}; \node[above of=le,xshift=10mm] (ar) {Aristotle}; \node[left of=ar] (ch) {Chrysippus}; \node[right of=ko] (co) {Colmerauer}; \node[above of=co] (po) {Post}; \node[left of=ko] (mc) {McCarthy}; \node[above of=mc] (ta) {Tarski}; \node[left of=mc] (mi) {Minski}; \node[left of=ta,node distance=30mm] (fr) {Frege}; \node[above of=fr] (bo) {Boole}; \node[below of=co,xshift=-5mm,fill=green!50!black] (pr) {Prolog}; \node[below of=pr] (cl) {Clark}; \node[below of=mc,xshift=12mm] (mo) {Moore}; \node[below of=mc,xshift=-12mm] (re) {Reiter}; \node[left of=re] (do) {McDermott Doyle}; \node[below of=mc,node distance=40mm] (ge) {Gelfond Lifschitz}; \node[below of=ge,fill=green!50!black] (ap) {A-Prolog}; \foreach \x/\y in {ar/le,ch/le,le/ko,po/ko,po/co,bo/fr,fr/ta,ta/mi,ta/mc,ta/ko,mc/do,mc/re,mc/mo,mc/ge,mo/ge,ko/pr,co/pr,pr/cl,pr/ge,cl/ge,ge/ap} \draw[-stealth,shorten >=1mm] (\x) -- (\y); \end{tikzpicture} \end{document} While the solution is adequate, I'm not particularly satisfied with the manual layout of the nodes, and the way the edges are styled. I was perusing the various packages for drawing trees, and would like to have something that looks like the examples given in the documentation for the genealogytree package. I'm having trouble getting started however, particularly when it comes to connecting the levels of the tree, (McCarthy to McDermott and Reiter, but also to Gelfond (who also has Moore and Prolog) as ancestors. Is there anyone that can help me get started?

  • pdflatex not working anymore after updating pdflatex.ini and initexmf --dump=pdflatex
    by user140574 on August 3, 2017 at 10:36 am

    I tried to overcome the well known tex capacity exceed problem, when using large Surf-plot with many datapoints. I tried this by typing into the cmd (Windows 7, MikTex 2.9): initexmf --edit-config-file=pdflatex main_memory=5000000 extra_mem_bot=5000000 font_mem_size=5000000 pool_size=5000000 buf_size=5000000 **initexmf --dump=pdflatex** Now, pdflatex does not work anymore, a dvi is built, but no output. The log also says that the system maybe just failed. pdflatex is broke... Any Ideas? (I cannot think of a proper MWE.)

  • Transform Shape not working - TikZ
    by alegasalv on February 19, 2016 at 2:04 pm

    I'm trying to scale the whole picture but it's not working. \begin{tikzpicture} [scale=0.5, every node/.style={transform shape}] \tikzstyle{startstop} = [ellipse, draw=orange, thick, fill=orange!20, text width=5em, minimum height=4em, text centered, dashed] \tikzstyle{block} = [rectangle, draw=blue, thick, fill=blue!20, text width=8em, minimum height=4em, shape aspect=2, text centered, rounded corners] % Define nodes in a matrix \matrix [column sep=10mm, row sep=7mm] { \node [startstop] (Signal) {Trama de la señal}; &\node [block] (DFT) {Transformada Discreta de Fourier}; &\node [block] (Module) {Módulo}; &\node [block] (MelFilt) {Filtros Mel}; \\ \node [startstop] (MFCC) {MFCC}; &\node [block] (Lifter) {Lifter}; &\node [block] (IDCT) {Transformada Discreta Inversa de Coseno}; &\node [block] (Log) {Logaritmo}; \\ }; \node [draw, scale=1, rectangle, dashed, thick, fit=(DFT) (Module) (Log) (Lifter) (IDCT)] {}; % connect all nodes DFT above \begin{scope} [every path/.style={line, line width=1.3pt} ] %Down Lines \path (Signal) -- (DFT); \path (DFT) -- (Module); \path (Module) -- (MelFilt); \path (MelFilt.south) -- (Log.north); \path (Log) -- (IDCT); \path (IDCT) -- (Lifter); \path (Lifter) -- (MFCC); \end{scope} \end{tikzpicture} And when I replace transform shape for scale=0.5, the fitting fails.

  • Problems at page boundaries trying to highlight `\lstinline`
    by JLDiaz on July 15, 2013 at 5:05 pm

    I was trying the code given in Colored background in inline listings, which is actually the same than in How to redefine \lstinline to automatically highlight or draw frames around all inline code snippets?, and I ran into the following problem. When the paragraph in which the \lstinline appears is broken among pages, the highlight goes to the wrong page (not always). It also happens even if the paragraph is not broken, when latex footnotes or floating mechanism interferes and sends that paragraph to the next page. The following MWE shows both problems. It is the same code than in the cited answers, with some more text before the example which causes the problem for the first case (page-break at the paragraph). You can uncomment the line with the footnote, near \begin{document}, to see also the second problem (the whole paragraph goes to the next page, but the highlight remains in the first page). \documentclass[a4paper]{article} \usepackage{etoolbox} \usepackage{atbegshi,ifthen,listings,tikz} \usepackage{lipsum} % change this to customize the appearance of the highlight \tikzstyle{highlighter} = [ yellow,% set the color for inline listings here. line width = \baselineskip, ] % enable these two lines for a more human-looking highlight %\usetikzlibrary{decorations.pathmorphing} %\tikzstyle{highlighter} += [decorate, decoration = random steps] % implementation of the core highlighting logic; do not change! \newcounter{highlight}[page] \newcommand{\tikzhighlightanchor}[1]{\ensuremath{\vcenter{\hbox{\tikz[remember picture, overlay]{\coordinate (#1 highlight \arabic{highlight});}}}}} \newcommand{\bh}[0]{\stepcounter{highlight}\tikzhighlightanchor{begin}} \newcommand{\eh}[0]{\tikzhighlightanchor{end}} \AtBeginShipout{\AtBeginShipoutUpperLeft{\ifthenelse{\value{highlight} > 0}{\tikz[remember picture, overlay]{\foreach \stroke in {1,...,\arabic{highlight}} \draw[highlighter] (begin highlight \stroke) -- (end highlight \stroke);}}{}}} %-------------------------- \makeatletter % Redefine macros from listings package: \newtoggle{@InInlineListing}% \togglefalse{@InInlineListing}% \renewcommand\lstinline[1][]{% \leavevmode\bgroup\toggletrue{@InInlineListing}\bh % \hbox\bgroup --> \bgroup \def\lst@boxpos{b}% \lsthk@PreSet\lstset{flexiblecolumns,#1}% \lsthk@TextStyle \@ifnextchar\bgroup{\afterassignment\lst@InlineG \let\@let@token}% \lstinline@}% \def\lst@LeaveAllModes{% \ifnum\lst@mode=\lst@nomode \expandafter\lsthk@EndGroup\iftoggle{@InInlineListing}{\eh{}}{}% \else \expandafter\egroup\expandafter\lst@LeaveAllModes \fi% } \makeatother \lstset{backgroundcolor=\color{green!10}}% \begin{document} \lipsum[1-5] % Foo\footnote{\lipsum[6]} This is a somewhat large paragraph which latex perhaps will break among two pages. Hopefully this will show the intended problem, that is, that the highligthed yellow box is shown in the page in which the paragraph started, instead of the page in which the code actually landed. Some more sentences to fill the required space will do. Blah, blah, lorem ipsum or whatever. This is a test where \lstinline{A=1} should have a yellow background. This, on the other hand, actually works: \begin{lstlisting}[backgroundcolor=\color{green}] A = 1 \end{lstlisting} \end{document} This is the result (after compiling twice). The yellow box near "ipsum" should be on the A=1 inline code of the second page. Can this be fixed?

  • Different background colors for lstinline
    by projetmbc on April 7, 2012 at 12:09 am

    In the following code, I've decided to use the code from Colored background in inline listings so as to redefine \verb to have the possibility to use colors for the text and the background of the verbatim text. The problem I meet is that only one color for the background can be used by page and I would like to have different background colors in the same page. This is surely the consequence of the use of the style: \tikzstyle{highlighter} = [% \bck@color, % line width = 0.9\baselineskip% ] What are the changes to do in the following code? Another question: is it possible to have a border rule with also a customizable color? % Two compilations must be done ! \documentclass{article} \usepackage[utf8]{inputenc} % == EXTRA == % \setlength{\parindent}{0cm} % == PACKAGES USED == % \usepackage{xargs} \usepackage{etoolbox} \usepackage{atbegshi} \usepackage{ifthen} \usepackage[svgnames,x11names]{xcolor} \usepackage{tikz} \usepackage{listings} % == DEF : Verbatim with color option == % \definecolor{colorCodeNormal}{named}{black} \definecolor{colorCodeBack}{named}{Snow2} \lstset{backgroundcolor=\color{colorCodeBack}}% \makeatletter \newcounter{highlight}[page] \newcommand{\tikzhighlightanchor}[1]{% \ensuremath{% \vcenter{% \hbox{% \tikz[remember picture, overlay]{ \coordinate (#1 highlight \arabic{highlight}); }% }% } }% } \newcommand{\bh}[0]{\stepcounter{highlight}\tikzhighlightanchor{begin}} \newcommand{\eh}[0]{\tikzhighlightanchor{end}} \AtBeginShipout{% \AtBeginShipoutUpperLeft{ \ifthenelse{\value{highlight} > 0}{\tikz[remember picture, overlay]{\foreach \stroke in {1,...,\arabic{highlight}} \draw[highlighter] (begin highlight \stroke) -- (end highlight \stroke);}}{} } } \newtoggle{@InInlineListing}% \togglefalse{@InInlineListing}% \renewcommand\lstinline[1][]{% \leavevmode\bgroup\toggletrue{@InInlineListing}\bh % \hbox\bgroup --> \bgroup \def\lst@boxpos{b}% \lsthk@PreSet\lstset{flexiblecolumns,#1}% \lsthk@TextStyle \@ifnextchar\bgroup{\afterassignment\lst@InlineG \let\@let@token}% \lstinline@}% \def\lst@LeaveAllModes{% \ifnum\lst@mode=\lst@nomode \expandafter\lsthk@EndGroup\iftoggle{@InInlineListing}{\eh{}}{}% \else \expandafter\egroup\expandafter\lst@LeaveAllModes \fi% } \renewcommand\verb{% \@ifstar{% \lstset{% showspaces=true,% showtabs=true% }% \@verbItInColor% }{% \lstset{% showspaces=false,% showtabs=false%% }% \@verbItInColor% }% } \newcommandx\@verbItInColor[2][% 1=colorCodeNormal,% 2=colorCodeBack ]{% \ifx\relax#1\relax \edef\txt@color{colorCodeNormal}% \else \edef\txt@color{#1}% \fi \ifx\relax#2\relax \edef\bck@color{colorCodeBack}% \else \edef\bck@color{#2}% \fi \lstset{basicstyle=\ttfamily\color{\txt@color}}% \tikzstyle{highlighter} = [% \bck@color, % line width = 0.9\baselineskip% ] \lstinline% } \makeatother \begin{document} % On this first page there is a problem. \verb+NORMAL+ \verb[blue]+BLUE+ \verb[green][DarkViolet]+GREEN ON DARK VIOLET+ \verb[white][cyan]+WHITE ON CYAN+ \newpage % Here the background color is correct. \verb[white][red]+WHITE ON RED+ \newpage % Here again the backgorund color is the good one. \verb[green][DarkViolet]+GREEN ON DARK VIOLET+ \end{document}

  • Why is tikz so much slower when plotting a huge amount of data than WYSIWYG plotting tools?
    by Philipp on January 23, 2012 at 10:00 am

    I was wondering why a tikz/pgf plot of a data file containing several thousand data points needs a couple of minutes to compile while creating the same plot with a WYSIWYG plotting tool (like Grace) or spreadsheet application (like MS Excel or Origin) needs only seconds. What are the WYSIWYG applications doing differently from tikz to be so much faster?

  • Cool Text Highlighting in LaTeX
    by Andrew Starks on November 25, 2010 at 5:13 pm

    LaTeX has soul. ConTeXt, of course, has beautifully marked up "sharpie" highlighting, where you can put sweet hightligher under your text for free! In the pictured example, you can see highlights that not only highlight, but that do it with cool edges that look so good, you can smell fumes! The fearless author says he'll show how that was done in another post; this one shows only how to lay down a straight, yellow box. But, it is possible to do word-wrapped highlighting with cool-shapped boxes within ConTeXt, presumably. The trouble for me is that getting into the ConTeXt world is steep climb right now, given the state of documentation and the flux of changes, so I need to continue with LaTeX. But the real problem is that now I can't live without the Organic-Looking Highlights of Awesomeness in that picture! As I said, Non-Organic-Looking Highlights of the Ordinary are easy with the soul package: \hl{Some awesome text that word wraps fine.} It just taunts me on the page with its straight lines. So, if I sacrifice word wrapping, I can use PGF/TiKz and create the following macro: \newcommand\hl[1]{% \tikz[baseline,% decoration={random steps,amplitude=1pt,segment length=15pt},% outer sep=-15pt, inner sep = 0pt% ]% \node[decorate,rectangle,fill=navcolor,anchor=text]{#1\xspace};% }% Which creates something like this: Now, my color is too dark and my randomness needs adjusting, but you see that a similar effect could be achieved. My trouble is that I don't understand TeX enough to dig into the Soul package and add the TiKz/PGF goodness that it so sorely needs. So, I leave it to you guys. Anyone want to tackle this? Or is it yet another piece of fruit, just a touch out of reach, that shall have to wait until ConTeXt settles down?