Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using a two sided layout in LaTeX and have several places where white space could be filled with images instead of being included in the text flow. I cannot get a working figure with caption though.

What I have tried from similar questions:

Throws "Argument of \Gin@ii has an extra }"

\marginpar{\includegraphics[width=\marginparwidth]{myimage.jpg}
 \captionof{figure}{Caption text}}
\lipsum[1-2]

This works but does not appear in the \listoffigures:

\marginpar{  
\centering{  
\includegraphics[width=\marginparwidth]{myimage.jpg}  
}  
Caption text  
} 

The caption is supposed to have a generated index and link to the list of figures.

EDIT: a longer example

\documentclass[11pt, a4paper, titlepage]{book}
\usepackage{booktabs}
\usepackage{color,graphicx}
\usepackage{geometry}

\usepackage[utf8]{inputenc}
\usepackage{varwidth}  

\usepackage{ngerman}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\graphicspath{{images/}}



\geometry{  a4paper,
            twoside,
            includemp,
            includehead,
            top = 30mm,
            headsep = 10mm,
            bindingoffset = 10mm,
            inner = 20mm,
            outer = 40mm,
            bottom = 45mm,
            marginparsep = 10mm,
            marginparwidth = 30mm
}
\savegeometry{myText}


\begin{document}
\tableofcontents

\chapter{Chapter about XY}
 aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo i

%%
% image with caption to go to the margin with its caption
%%
 \begin{figure}[t!bp]%
    \begin{center}%
        \includegraphics{ant}%
        \caption[Caption]{Caption text}
        \label{label}%
    \end{center}%
\end{figure}%

% creates the image in the margin but without link in TOC and list of figures
\marginpar{  
\centering{  
\includegraphics[width=\marginparwidth]{ant.jpg}  
}  
Caption text  
} 

 aeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo 

 \end{document}

EDIT: This is working for me, why are the {} wrong?:

\marginpar{  
\centering{  
\includegraphics[width=\marginparwidth]{example-image-a.jpg}  
}  
\captionof{figure}{Caption text}
}

Also: adding a different text for the index tabel with

\captionof{figure}[table text]{Caption text}

causes "Argument of \caption@ydblarg has an extra }."

share|improve this question

migrated from stackoverflow.com Oct 4 '13 at 7:27

This question came from our site for professional and enthusiast programmers.

    
What does not work for you in the first code snippet? Using it in a minimal document works without problem. –  Werner Sep 26 '13 at 17:20
    
In a minimal document it throws a "undefined control sequence in line" \captionof{figure}{Caption text}} –  RootRaven Sep 27 '13 at 0:21
    
You need either the capt-of or the caption package loaded. The latter is preferred (\usepackage{caption}). –  Werner Sep 27 '13 at 0:55
    
This works fine but the caption is not included in the figure table. –  RootRaven Oct 4 '13 at 4:25
1  
No problems where with your example if I use the demo option for graphicx (to avoid needing your pictures). Do you get the problem with exactly that file? If so, add \listfiles and edit the resulting file list from the .log into the question. –  Joseph Wright Oct 6 '13 at 16:27

1 Answer 1

I hope I understand you right. I have changed the part of your MWE for the image in the margins. It should compile now. I added package caption in the preambel and corrected the call of \centering (without {}!). And I added \listoffigures to show that the image in the margin listed there. I use the example-image-a.jpg from package MWE.

The MWE:

\documentclass[11pt, a4paper, titlepage]{book}
\usepackage{booktabs}
\usepackage{color,graphicx}
\usepackage{geometry}

\usepackage[utf8]{inputenc}
\usepackage{varwidth}  

\usepackage{ngerman}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}

\usepackage{caption}       % <============================
\usepackage{showframe}     % <============================
%\graphicspath{{images/}}

\geometry{  a4paper,
            twoside,
            includemp,
            includehead,
            top = 30mm,
            headsep = 10mm,
            bindingoffset = 10mm,
            inner = 20mm,
            outer = 40mm,
            bottom = 45mm,
            marginparsep = 10mm,
            marginparwidth = 30mm
}
\savegeometry{myText}


\begin{document}
\tableofcontents
\listoffigures

\chapter{Chapter about XY}
 aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo i

%%
% image with caption to go to the margin with its caption
%%
 \begin{figure}[t!bp]%
    \begin{center}%
        \includegraphics[width=\columnwidth]{example-image-a}%
        \caption[Caption]{Caption text}
        \label{label}%
    \end{center}%
\end{figure}%

% creates the image in the margin but without link in TOC and list of figures
\marginpar{  
  \centering       % <============================
  \includegraphics[width=\marginparwidth]{example-image-a.jpg}  
  \captionof{figure}{Caption text}
} 

 aeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo iaeoiaeo iaeoiaeo aeo eaoiaeoiaeoi oiaeo iaeoiaeo 

 \end{document}

Result:

enter image description here

Please have a look to question when-should-we-use-begincenter-instead-of-centering to see the difference between environment center and macro \centering.

Just a remark to th

share|improve this answer
    
Thank you! The MWE works as expected but if I copy the code to my project, I get the same error "Argument of \Gin@ii has an extra }". See the edit –  RootRaven Oct 6 '13 at 16:14
    
@RootRaven Macro \centering is used to center all following parts. If you write \begin{figure}\centering then centering works until \end{figure}is reached. If you search for LaTeX \Gin@ii you will find several messages, that there is a problem with wrong or too much brackets {} or [] with macro \includegraphics. Please check your code for this ... –  Kurt Oct 6 '13 at 16:28
    
How can I have too many brackets if the file compiles fine and I only pasted the \marginpar snipped? –  RootRaven Oct 6 '13 at 16:43
    
@RootRaven Sorry, saw your response just now. Understand I right: Compiling my MWE: no problems, error, warnings. After coppying my margin solution in your code you have problems? Then the reason must be found in your code. copy my MWE, add step by step your used packages into the copy, compile and so on until you find the reson for the error. No keep the last package in the copy and delete the other ones you added. Compile. Error? Good, you found an MWE to be added to your question. No error? Try to find the package combination and order causing the error ... –  Kurt Oct 8 '13 at 22:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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