6

I'm trying to insert a picture besides the chapter title using this code

‎\begin{document}‎
\chapter{for example}
\begin{figure}[h]
\includegraphics[width=20mm]{turing.png}
\end{figure}‎

but the picture is inserted in a new line. Can I specify a coordinate for inserting a picture there?

  • If you want the picture inside the caption, you don't want to float it. Therefore you do not want to use the figure environment. You may specify your image command directly into the \chapter{..}, though depending on the height it may look very odd. If you need more assistance please provide a MWE and probably a screenshot showing us your desired Output. – Martin - マーチン Jul 15 '13 at 11:50
  • I get "use of chapter doesn't match its definition" if I try that. – JakobMST Jul 15 '13 at 12:05
  • Is this something that will be used for every chapter or just for some of them? – Gonzalo Medina Jul 15 '13 at 13:18
10

You can use TikZ; the tikzpagenodes gives you easy control on the positioning using the anchors for the text area:

\documentclass{book}
\usepackage{graphicx}
\usepackage{tikzpagenodes}
\usepackage{lipsum}

\begin{document}‎

\chapter{Test chapter}
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=east,inner sep=0pt] at (current page text area.east|-0,3cm) {\includegraphics[height=3cm]{example-image-a}};
\end{tikzpicture}

\lipsum[4]

\end{document}

enter image description here

4

Since I'm getting complaints trying to include a graphic within the \chapter-command's argument, here's what worked for me:

This is more than anything a hack, But one thing you can do is to include the graphic in the next line and move it up with a negative \vspace. You can use any unit, but I believe it's best to use something like \baselineskip which is contextually defined rather than an absolute unit like mm or pt for the height of the vertical space. Be sure to include a positive \vspace afterwards to avoid squeezing the body of the chapter to the caption.

If you want to have a graphic to go with all your chapters, you can pack all of this into a macro which behaves like chapter except that it expects a second argument referencing a figure, like so:

    \documentclass[final]{book}
\usepackage{graphicx, ifthen}

    \newcommand{\mychapter}[3][\empty]{%
        \ifthenelse{\equal{#1}{\empty}}% check whether optional parameter is empty
                         {\chapter[#2]{#2}}% 
                         {\chapter[#1]{#2}}% 
        {\Huge %
           \vspace{-2.2\baselineskip} % move up
           \hfill % move graphic right
           \includegraphics[height=10mm]{#3} % include graphic
           \vspace{\baselineskip} % move down before body starts
        }% delimit scope of \Huge
    }

\begin{document}‎
\tableofcontents

\mychapter[toc title]{A chapter}{Logo-univie}%different title in TOC and heading

\mychapter{Another chapter}{Logo-univie}%same title everywhere

Some text
\end{document}

NOTE: Edited to preserve the optional argument of \chapter.

  • It should be noted, though, that neither this solution nor yours can handle really long chapter titles. – JakobMST Jul 15 '13 at 14:50
2

If you specify a graphic in a chapter command, you will have to protect that command, so that it will not be interpreted when writing the toc file Or specify another heading:

\documentclass[12pt, a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[demo]{graphicx}

\begin{document}
\tableofcontents

\chapter{looks odd in TOC \protect\includegraphics[width=20mm]{test.png}}
\chapter[does not look so odd in TOC (because the graphic is missing)]%
        {does not look so odd in TOC \includegraphics[width=20mm]{test.png}}

\end{document}

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.