0

I was trying to use a tikzpicture using a robust custom command in a section title as is it described here. I'm not getting error when using the robust command but my custom symbols definition is printed after the correct symbol and section title. In a normal text everything works perfectly fine, tough. The command for the picture I got from here.

\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\newlength\Size
\setlength\Size{4pt}
\DeclareRobustCommand\customFile{
    \begin{tikzpicture}[#1]{
    \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ;
}
   \end{tikzpicture}
}

When I use the custom command in a section the definition of the folder symbol is printed after the section:

\subsubsection{\customFolder{} bubbleInterTrackFoam}

Any suggestions what may this problem? Thanks in advance!

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – dexteritas Jan 16 '20 at 12:48
  • If you REALLY want to make it robust (and faster), use a savebox. – John Kormylo Jan 17 '20 at 17:34

1 Answers1

1

Adaptations:

  • created MWE
  • removed parameter #1 from definition
  • use defined \customFile instead of undefined \customFolder

Code:

\documentclass{article}

\usepackage{tikz}

\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\newlength\Size
\setlength\Size{4pt}
\DeclareRobustCommand\customFile{
    \begin{tikzpicture}{
        \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ;
    }
    \end{tikzpicture}
}

\begin{document}
    \section{\customFile bubbleInterTrackFoam}
    \subsection{\customFile bubbleInterTrackFoam}
    \subsubsection{\customFile bubbleInterTrackFoam}
\end{document}

Result:

enter image description here

dexteritas
  • 9,161
  • Hey dexteritas, thanks for your help and the quick reply. I see now that the error happens due to the custom document class I'm using to write my thesis. I am using [this] (https://www.overleaf.com/latex/templates/template-for-a-masters-slash-doctoral-thesis/mkzrzktcbzfl) template, which reproduces the error when I use your code. :( – yummigummi Jan 16 '20 at 15:03
  • If you want further comments on your problem you should make a minimal working example (MWE) as I suggested above. You can edit your question for this. – dexteritas Jan 16 '20 at 15:47