6

I have googled forever and tried to find the answer to my question, but I can't seem to find an answer to this. I have two figures that I want to place beside each other. The figures are MATLAB plots and are saved as pdfs, therefore they have to be clipped and scaled to get an okay size in my latex file. I have tried to put the figures beside each other by using minipage and this works, but the figures are too large to fit within the text width, so some parts of the figures are not showing. Can anyone please help me with this?

As of now my latex code looks like this:

\begin{figure}[H]
    \begin{addmargin*}[0cm]{-3cm}
    \begin{minipage}{0.5\textwidth}
    \centering
    \includegraphics[trim={1.4cm 7.5cm 2.0cm 7.5cm},clip, scale = 0.5]{figure1}
    \caption{Caption one.}
    \end{minipage}  

    \begin{minipage}{0.5\textwidth}
    \includegraphics[trim={1.4cm 7.5cm 2.0cm 7.5cm},clip, scale = 0.5]{figure2}
    \caption{Caption two.}
    \end{minipage}
    \end{addmargin*}
\end{figure}
kga
  • 71
  • No, it does'n really... I still don't get extra margin space. I edited my code to the following, but it doesn't help.

    \begin{figure}[H] \begin{addmargin*}[0cm]{-3cm} \begin{minipage}{0.5\textwidth} \centering \includegraphics[trim={1.4cm 7.5cm 2.0cm 7.5cm},clip, scale = 0.5] {figure1} \caption{Flower one.} \end{minipage}

    \begin{minipage}{0.35\textwidth}
    \includegraphics[trim={1.4cm 7.5cm 2.0cm 7.5cm},clip, scale = 0.5] {figure2}
    \caption{Flower two.}
    \end{minipage}
    \end{addmargin*}
    

    \end{figure}

    – kga Dec 16 '15 at 13:28
  • Also, how do you get the code to look nice like it was edited to in the question? – kga Dec 16 '15 at 13:31
  • In the question, mark the code and press Ctrl and k. In comments, this does not work. Please edit your question to include the modified code, and please make the exampe compilable. That is the only way, we are talking about the same problem. – Johannes_B Dec 16 '15 at 14:02
  • Thank you. The only thing I updated was to add the addmargin part, and that didn't work, so I guess it's okay to keep the code as it is? – kga Dec 16 '15 at 14:06
  • No, it is not. You say it does not work, but it obviously worked in the answer i linked. That means you are doing something different, and providing a minimal working example is the only way for us to see the difference. – Johannes_B Dec 16 '15 at 14:09
  • Of course, sorry. The code is edited now. – kga Dec 16 '15 at 14:22
  • 1
    Without the files figure1 and figure2, there is not a lot we can do. One thing, if you want them side by side you need to lose the blank line. That starts a new paragraph. – John Kormylo Dec 16 '15 at 19:12
  • for the figure on the left, try \leavevmode\hspace*(-3cm}\includegraphics ...; for the figure on the right, insert the negative \hspace to the right of the \includegraphics. and lose the blank line between the two minipages as already mentioned. if you want the captions centered on the graphics, insert the \leavevmode and\hspaces outside the minipages, and end the line with\par`. – barbara beeton Dec 16 '15 at 19:27

3 Answers3

2

If you do not have a twoside document then you can ignore the \ifthispageodd line

\documentclass[twoside]{scrartcl}
\usepackage{mwe}
\usepackage{showframe}
\newlength\fullwidth
\setlength\fullwidth{\dimexpr\textwidth+\marginparwidth+\marginparsep\relax}
\newenvironment{Figure}
  {\begin{figure}[!htb]%
   \ifthispageodd{}{\hspace*{\dimexpr-\marginparsep-\marginparwidth}}%
   \minipage{\fullwidth}}
  {\endminipage\end{figure}}

\begin{document}
\blindtext\newpage\blindtext

\begin{Figure}
\begin{minipage}[b]{0.49\linewidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{Caption one.\label{bar}}
\end{minipage}\hfill
\begin{minipage}[b]{0.49\linewidth}
    \includegraphics[width=\linewidth]{example-image-16x10}
    \caption{Caption two.}
\end{minipage}
\end{Figure}

\blindtext
\begin{Figure}
\begin{minipage}{0.49\linewidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{Caption one.}
\end{minipage}\hfill
\begin{minipage}{0.49\linewidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{Caption two.\label{foo}}
\end{minipage}
\end{Figure}

As seen in Figure~\ref{bar} on page~\pageref{bar} \ldots

\Blindtext

As seen in Figure~\ref{foo} on page~\pageref{foo} \ldots

\end{document}

enter image description here

1

Evidently addmargin does not change \textwidth.

\documentclass{scrartcl}
\usepackage{mwe}
\usepackage{showframe}

\begin{document}
\begin{figure}
    \begin{addmargin*}[0cm]{-3cm}%
    \begin{minipage}{0.5\linewidth}
    \centering
    %\includegraphics[trim={1.4cm 7.5cm 2.0cm 7.5cm},clip, scale = 0.5]{figure1}
    \rule{\textwidth}{1in}
    \caption{Caption one.}
    \end{minipage}%
    \begin{minipage}{0.5\linewidth}
    \centering
    %\includegraphics[trim={1.4cm 7.5cm 2.0cm 7.5cm},clip, scale = 0.5]{figure2}
    \rule{\textwidth}{1in}
    \caption{Caption two.}
    \end{minipage}
    \end{addmargin*}
\end{figure}
\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
0

For such cases is designed the package changepage. With its macro adjustwidth (for one side documents) or adjustwidth* (for two side documents) you will obtain:

enter image description here

The code for above picture:

\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{showframe}
\usepackage{calc}% <--- added
\usepackage[strict]{changepage}% <--- added

\begin{document}
\begin{figure}
\begin{adjustwidth*}{}{-\marginparwidth-\marginparsep}
    \begin{minipage}[b]{0.49\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{Caption one.}
    \end{minipage}
\hfill
    \begin{minipage}[b]{0.49\linewidth}
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{Caption two.}
    \end{minipage}
\end{adjustwidth*}
\end{figure}
\end{document}
Zarko
  • 296,517
  • for a one sided document you do not need changepage. A simple minipage will do –  Feb 15 '16 at 13:02
  • Yes, in this cases you can stick with minipage˛ and warning overfull .... Beside simple use here, the changepage offer consistent flexibility for local changes of text width. Obvious, I liked this package :-) – Zarko Feb 15 '16 at 13:12