1

I need to strictly use the format of the paper since it was given from the University. The margin of the text is 12.5cm and the one of the figures too. I need to put the label of the figure on its right (on the "white" margin of the paper).

I copy my code below.

Thank you very much.

\documentclass[10pt,a4paper,openright]{book}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{floatrow}

\usepackage[labelfont=bf]{caption}
\usepackage{setspace}
\captionsetup{font={footnotesize,stretch=1.2}}
\usepackage{eso-pic}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage[colored]{shadethm}
\usepackage{color, xcolor}
\usepackage{pstricks, colortab}
\usepackage{fancyhdr} 
\usepackage{makecell}
\usepackage{url}


\setlength{\topmargin}{-1.2 cm} 
\setlength{\oddsidemargin}{0.2 cm} 
\setlength{\evensidemargin}{3.2 cm}
\setlength{\textwidth}{12.5 cm} 
\setlength{\textheight}{24.5 cm} 

\linespread{1.2}\selectfont

\pagestyle{fancy}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth} 
\fancyhf{}




\begin{document}

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text


\begin{figure}[h]

\centering
\includegraphics[width=12.5cm]{figure.pdf}
\caption{capture}
\captionsetup{font={small,stretch=1.2}}
\label{fig1}

\end{figure}

\end{document}

\endinput
  • Welcome to TeX.SE. Or load into your code \usepackage{amsfonts} or load \usepackage{amssymb}. Why do you use color and xcolor? – Sebastiano Feb 26 at 18:26
  • The original code was given to me from my university. I do not know why.. – Michele Feb 27 at 9:37
2

I'm assuming that you are using label to mean the LaTeX construct caption. Following is an edited version of your MWE which uses the sidecap package (read the documentation via texdoc sidecap) to put captions at the side of floats.

% labelfigprob.tex  SE 530139 label on margin of figure

\documentclass[10pt,a4paper,openright]{book}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{floatrow}

\usepackage[labelfont=bf]{caption}
\usepackage{setspace}
\captionsetup{font={footnotesize,stretch=1.2}}
\usepackage{eso-pic}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage[colored]{shadethm}
\usepackage{color, xcolor}
\usepackage{pstricks, colortab}
\usepackage{fancyhdr} 
\usepackage{makecell}
\usepackage{url}


\setlength{\topmargin}{-1.2 cm} 
\setlength{\oddsidemargin}{0.2 cm} 
\setlength{\evensidemargin}{3.2 cm}
\setlength{\textwidth}{12.5 cm} 
\setlength{\textheight}{24.5 cm} 

\linespread{1.2}\selectfont

\pagestyle{fancy}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth} 
\fancyhf{}

\usepackage{sidecap}



\begin{document}

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text


%\begin{figure}[h] % sidecap uses SCfigure instead of figure
\begin{SCfigure}[][h]

\centering
%\includegraphics[width=12.5cm]{figure.pdf} % I don't have this
%\includegraphics[width=12.5cm]{example-image-a} % this comes with the graphicx package
\includegraphics[width=6cm]{example-image-a} % reduce width of figure if necessary to provide more space for the side caption
\caption{capture}
\captionsetup{font={small,stretch=1.2}}
\label{fig1}

%\end{figure}
\end{SCfigure}

\end{document}

EDIT with another solution

I have tried various sidecap solutions but with your required page layout the captions are always as small as possible (I think that the side caption is meant to be within the textwidth which in your case is filled by your figure).

The memoir class (a superset of the book, report and article classes) provides the sidecaption environment for captions to be placed in the margin, which I think is what you are after (read the documentation texdoc memoir Side Captions for full information).

The following is an edited version of your MWE using the memoir class instead of book and not using the floatrow or the caption package as memoir provides its own facilities for these.

% labelfigprob2.tex  SE 530139 label on margin of figure

\documentclass[10pt,a4paper,openright]{memoir}
\usepackage{comment}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lipsum}
%\usepackage{floatrow} % not good with memoir (\newfloat already defined)

%\usepackage[labelfont=bf]{caption} % memoir has its own views about captions
\usepackage{setspace}
%\captionsetup{font={footnotesize,stretch=1.2}}
\usepackage{eso-pic}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage[colored]{shadethm}
\usepackage{color, xcolor}
\usepackage{pstricks, colortab}
\usepackage{fancyhdr} 
\usepackage{makecell}
\usepackage{url}

% memoir has its own methodes for page dimensions, but these work OK
\setlength{\topmargin}{-1.2 cm} 
\setlength{\oddsidemargin}{0.2 cm} 
\setlength{\evensidemargin}{3.2 cm}
\setlength{\textwidth}{12.5 cm} 
\setlength{\textheight}{24.5 cm} 

\linespread{1.2}\selectfont

\pagestyle{fancy}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth} 
\fancyhf{}

\sidecapmargin{outer} % put the captions in the outer margin

\begin{document}

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

\begin{figure}
\begin{sidecaption}{capture}[fig1]
\centering
\includegraphics[width=12.5cm]{example-image-a}
\end{sidecaption}
\end{figure}

\end{document}

Hope this helps.

|improve this answer|||||
  • Thank you @peter, however I need to keep both the text width and the figure width equal to 12.5cm. Then, I would like to put the caption on the side of the figure (out of the margin). If I try to use your code assuming that the figure width=12.5cm, then the caption is too narrow. – Michele Feb 27 at 9:27
  • Thank you @Peter, it is almost perfect. I have just a small issue now. The margins of the paper are different, from the right page to the left page. So, the caption of the figure should be placed on the right and on the left of the text, depending on the margins. Now the captions are always put on the right. – Michele Feb 28 at 11:05
  • @Michele In my MWE the captions are put in the outer margin. Please read the memoir documentation regarding the placement of the captions. I'm not at all sure what you are after. – Peter Wilson Feb 28 at 19:24
1

A supplement to Peter Wilson answer (+1). If I correctly understood your question, you like to have captions in page borders. For this you need to enclose image and caption in wide environment:

\documentclass[10pt,a4paper,openright]{book}
\setlength{\topmargin}{-1.2 cm}        
\setlength{\oddsidemargin}{0.2 cm}
\setlength{\evensidemargin}{3.2 cm}
\setlength{\textwidth}{12.5 cm}
\setlength{\textheight}{24.5 cm}

\linespread{1.2}\selectfont

\usepackage{graphicx}
\usepackage{setspace}
\usepackage[labelfont=bf]{caption}
\captionsetup{font={small,stretch=1.2}}


\usepackage[rightcaption]{sidecap}
\usepackage{lipsum}


\begin{document}
\lipsum[1]
%
\begin{SCfigure}[1][!ht]%
    \begin{wide}%  
\includegraphics[width=\textwidth]{example-image-duck} % this comes with the graphicx package
    \caption{capture}
    \label{fig1}
\end{wide}
\end{SCfigure}
%
\lipsum[2]
\end{document}

enter image description here

(red lines indicate page layout)

Addendum: Now it seems that you like to have caption on outside margins. In this case replace in above MWE

\usepackage[rightcaption]{sidecap}

with

\usepackage[outercaption]{sidecap}

This will after two compilation of will give:

enter image description here

Above image is generated by:

\documentclass[10pt,a4paper,openright]{book}
\setlength{\topmargin}{-1.2 cm}
\setlength{\oddsidemargin}{0.2 cm}
\setlength{\evensidemargin}{3.2 cm}
\setlength{\textwidth}{12.5 cm}
\setlength{\textheight}{24.5 cm}

\linespread{1.2}\selectfont

\usepackage{graphicx}
\usepackage{setspace}
\usepackage[labelfont=bf]{caption}
\captionsetup{font={small,stretch=1.2}}

\usepackage[outercaption]{sidecap}  % <---
% vertical position of caption
%\sidecaptionvpos{figure}{t} % at the top of image
%\sidecaptionvpos{figure}{c} % vertical centered
\usepackage{lipsum}

\begin{document}
\lipsum[1-3]
%
\begin{SCfigure}[1][!hb]%
    \begin{wide}%
\includegraphics[width=\textwidth]{example-image-duck} % this comes with the graphicx package
    \caption{capture}
    \label{fig1}
\end{wide}
\end{SCfigure}
%
\lipsum[3]
\begin{SCfigure}[1][!ht]%
    \begin{wide}%
\includegraphics[width=\textwidth]{example-image-duck} % this comes with the graphicx package
    \caption{capture}
    \label{fig1}
\end{wide}
\end{SCfigure}
\lipsum[4-5]
\end{document}
|improve this answer|||||
  • the second case is perfect to resolve my issue. thanks – Michele Mar 1 at 10:21
  • @Michele, I'm glad to hear this. Now you can accept my answer (by clicking on the check mark at top left side of answer) :-) – Zarko Mar 1 at 10:29

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.