3

I would like to add a little image to every Chapter, so I defined a macro with newcommand with an adjustable scale and tried to rename the chapter name. This is my MWE (actually, it doesn't work because the little image does not appear)

\documentclass{book}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}    
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\newcommand{\image}[1]{\begin{tikzpicture}[scale= #1] \draw[fill=blue] (0,0) circle(4pt); \end{tikzpicture} }
\addto\captionspanish{\renewcommand{\chaptername}{\image{0.18} Capítuloss}}
\begin{document}
\chapter{No name}
no named chapter
\end{document}

How I can make this small change? Does this will also leave the small picture in the header as name of the chapter?

  • Your example does not load package tikz. – Johannes_B Feb 29 '16 at 16:18
  • oh, but this is is not the problem, I forgot write usepackage{tikz} while I was wrinting my question. – Luis Felipe Feb 29 '16 at 16:19
  • I assume some missing \protect and your tikzpicture environment isn't closed – user31729 Feb 29 '16 at 16:19
  • Thanks anyway. What is \protect? how can I enable it or change it? – Luis Felipe Feb 29 '16 at 16:20
  • 1
    @Johannes_B You're right. I'll start testing little docs and see if it works – Luis Felipe Feb 29 '16 at 16:30
5

Using \renewcommand{\chaptername}{...} is possible \addto\captionsspanish{...} of course too. (Former trial version had a typo, that's why \addto\.... didn't work)

Anyway, \image is fragile due to the moving argument of \chapter and must be \protected.

\documentclass{book}
\usepackage[T1]{fontenc}    
\usepackage[utf8]{inputenc}

\usepackage[spanish]{babel}
\usepackage{tikz}
\newcommand{\image}[1]{%
  \begin{tikzpicture}[scale=#1]
    \draw[fill=blue] (0,0) circle(4pt);
  \end{tikzpicture}
}
\addto\captionsspanish{\renewcommand{\chaptername}{\protect\image{0.18}Capítulos}}


\begin{document}

\chapter{No name}
no named chapter
\end{document}

enter image description here

| improve this answer | |
  • 1
    This works. I'll look more about protect. Thanks – Luis Felipe Feb 29 '16 at 16:28
  • Why wouldn't you prefer \addto\captionsspanish instead of \AtBeginDocument? – egreg Feb 29 '16 at 16:35
  • @egreg: Because I made a typo and that's why it didn't work with \addto... – user31729 Feb 29 '16 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.