Graphics, Figures & TablesFigures Side by Side extended into Margin

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
abclatex
Posts: 17
Joined: Wed Nov 28, 2012 10:09 pm

Figures Side by Side extended into Margin

Post by abclatex »

Hi guys,

I have some problems of figures side by side.
  1. How to place figures like the "image1"? If someone could tell me how to manage them like "image2" (one figure occupies the body and has the same width as that of the body, while another occupies the margin and has the same width to that of the margin.), it could be perfect.
  2. How to place the figure caption directly under the figure? You can say the caption 2 of image 1 or 3 is at the wrong place.
Image 1
image 1.JPG
image 1.JPG (24.09 KiB) Viewed 7122 times
Image 2 (the ideal mode)
image 2.JPG
image 2.JPG (23.57 KiB) Viewed 7122 times
Image 3 (corresponding to the code)
image 3.JPG
image 3.JPG (30.9 KiB) Viewed 7122 times
Code:

Code: Select all

\documentclass[10pt,a4paper]{book}

% page layout
\usepackage[%
    left=2cm,
    right=7cm,
    top=2cm,
    bottom=2cm,
    textheight=25cm,
    textwidth=11cm,
    marginparsep=1cm,
    marginparwidth=5cm
    ]{geometry}

% Language settings
\usepackage[german,french]{babel}

% font and other typographic settings:
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Calibri-Light}
\usepackage{ragged2e}
\usepackage{ctex}
\usepackage{array,color}

% figures and the like:
\usepackage{graphicx}
\graphicspath{{fig/}}
\usepackage{caption}
\captionsetup[figure]{name={Figure.}}
\captionsetup{font={scriptsize,singlespacing},justification=RaggedRight,skip=2pt}
\usepackage{ifoddpage}
%or: \usepackage[strict]{changepage}
\usepackage{blindtext}

\begin{document}
\begin{figure}[t]
  %\setcapwidth{0.6\textwidth}
  \checkoddpage
  \edef\side{\ifoddpage l\else r\fi}%
  \makebox[\textwidth][\side]{%
    \begin{minipage}[t]{0.59\textwidth}
      \includegraphics[width=14cm]{1.1.jpg}
      \caption{Caption 1}
    \end{minipage}%
    \hspace{1cm}%
    \begin{minipage}[t]{0.59\textwidth}
      \raggedleft
      \includegraphics[width=3cm]{1.2.jpg}
      \caption{Caption 2}
      \label{fig:free-lunch}
    \end{minipage}%
  }%
\end{figure}

Today, four necktie knots are in widespread use. They are the four-in-hand knot, the half-Windsor knot, the Windsor knot and the Pratt knot. The first three are classic necktie knots that have been used for a long time. The Pratt knot is a more recent necktie knot that was introduced to the public in 1989.

Below shows a comparison table of the four necktie knots, together with the bow tie. It helps you find the answer to the first question that may come up in your mind -- Which necktie knots do I need? Click the links on the left to see the instructions on tying a certain knot.

\end{document}
Thanks a lot!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: Figures Side by Side extended into Margin

Post by cgnieder »

Is this a one-time occasion where you need a text figure and a margin figure side by side or will you figures always come in pairs? Should the figures be able to float like standard figures or should they be fixed?

Regards
site moderator & package author
abclatex
Posts: 17
Joined: Wed Nov 28, 2012 10:09 pm

Figures Side by Side extended into Margin

Post by abclatex »

cgnieder wrote:Is this a one-time occasion where you need a text figure and a margin figure side by side or will you figures always come in pairs? Should the figures be able to float like standard figures or should they be fixed?

Regards
Thanks for your reply, Cgnieder.

It' not one-time stuff. I need to place two or three figures side by side many times but not in every case. It's better to adopt float figures, I guess, since the paper has not done yet.

If I move the page layout codes, the overlapping would disppear. However I have to keep these layout codes.

Code: Select all

\usepackage[%
    left=2cm,
    right=7cm,
    top=2cm,
    bottom=2cm,
    textheight=25cm,
    textwidth=11cm,
    marginparsep=1cm,
    marginparwidth=5cm
    ]{geometry}
abclatex
Posts: 17
Joined: Wed Nov 28, 2012 10:09 pm

Re: Figures Side by Side extended into Margin

Post by abclatex »

Still unsolved...
aa3025
Posts: 1
Joined: Fri Aug 09, 2019 7:25 pm

Figures Side by Side extended into Margin

Post by aa3025 »

% if after 7 years someone is still interested in a possible solution using marginnote package:

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage{graphicx,marginnote,ragged2e}
\usepackage[%
left=2cm,
right=7cm,
top=2cm,
bottom=2cm,
textheight=25cm,
textwidth=11cm,
marginparsep=1cm,
marginparwidth=5cm
]{geometry}
\usepackage{blindtext}
\begin{document}\normalsize 
\vfill
		\includegraphics[width=0.99\linewidth]{figs/A2_exp}
\begin{center}
	Fig.111
\end{center}
\marginnote{
	\vspace{-60mm} % this require some tweaking to adjust vertical position is the same 
		\includegraphics[width=0.99\linewidth]{figs/A2_exp}
		\begin{center}
			Fig.222
		\end{center}
}
\justify
\blindtext 
\end{document}
figure_in_margins.png
figure_in_margins.png (100.62 KiB) Viewed 5303 times
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Figures Side by Side extended into Margin

Post by Ijon Tichy »

Nice, but marginnote is unmaintained. And manual figure numbers are not optimal.

One more suggestion using the KOMA-Script feature package scrextend to provide addmargin* and \ifthispagewasodd also for the standard class book. Users of a KOMA-Script class do not need to load the package.
\documentclass[10pt,a4paper]{book}
% If you'd use \documentclass[10pt]{scrbook} you would not need \usepackage{scrextend} later

% page layout
\usepackage[%
     left=2cm,
     right=7cm,
     top=2cm,
     bottom=2cm,
     %textheight=25cm, results from page size and left/right
     %textwidth=11cm, results from  page size and top/bottom
     marginparsep=1cm,
     marginparwidth=5cm
     ]{geometry}

% Language settings
\usepackage[ngerman,french]{babel}

% font and other typographic settings:
\usepackage{fontspec}
%\setmainfont[Ligatures=TeX]{Calibri-Light}% unknown font
\usepackage{ragged2e}
\usepackage{ctex}
\usepackage{array,color}

% figures and the like:
\usepackage{graphicx}
\graphicspath{{fig/}}
\usepackage{caption}
\captionsetup[figure]{name={Figure.}}
\captionsetup{font={scriptsize,singlespacing},justification=RaggedRight,skip=2pt}
\usepackage{scrextend}
%or: \usepackage[strict]{changepage}
\usepackage{mwe}

\begin{document}
% If the figures should be numbered from left to right:
\begin{figure}
  \begin{addmargin*}[0pt]{-\dimexpr \marginparwidth+\marginparsep\relax}
    \ifthispagewasodd
      \begin{minipage}[t]{\textwidth}
        \includegraphics[width=\textwidth]{example-image-a}
        \caption{Caption 1}
      \end{minipage}%
      \hspace{\marginparsep}%
      \begin{minipage}[t]{\marginparwidth}
        \includegraphics[width=\marginparwidth]{example-image-b}
        \caption{Caption 2}
        \label{fig:free-lunch}
      \end{minipage}%
    \else
      \begin{minipage}[t]{\marginparwidth}
        \includegraphics[width=\marginparwidth]{example-image-b}
        \caption{Caption 2}
        \label{fig:free-lunch}
      \end{minipage}%
      \hspace{\marginparsep}%
       \begin{minipage}[t]{\textwidth}
        \includegraphics[width=\textwidth]{example-image-a}
        \caption{Caption 1}
      \end{minipage}%
    \fi
  \end{addmargin*}
\end{figure}

\Blindtext[3]

% If the figure in the margin should always have the higher number:
\begin{figure}
  \begin{addmargin*}[0pt]{-\dimexpr \marginparwidth+\marginparsep\relax}
    \ifthispagewasodd\else\hspace*{\dimexpr\marginparwidth+\marginparsep\relax}\fi
    \begin{minipage}[t]{\textwidth}
      \includegraphics[width=\textwidth]{example-image-a}
      \caption{Caption 1}
    \end{minipage}%
    \ifthispagewasodd\hspace{\marginparsep}\else\hspace*{-\linewidth}\fi
    \begin{minipage}[t]{\marginparwidth}
      \includegraphics[width=\marginparwidth]{example-image-b}
      \caption{Caption 2}
      \label{fig:free-lunch-b}
    \end{minipage}%
  \end{addmargin*}
\end{figure}

\end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply