Home > Blockchain >  How to make pictures wider in LaTeX?
How to make pictures wider in LaTeX?

Time:10-14

I have tried to make a several pictures in one big figure. However, they are placed very close to each other. I need to add more space between them (between pictures in horizontal and in vertical).

Code:

\begin{figure}[h]
    \centering
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.6]{figs/solutions/transaction_solution.png}
        \caption{Transaction level isolation}
        \label{fig:subim1}
    \end{subfigure}
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.6]{figs/solutions/locking_solution.png}
        \caption{Record locking}
        \label{fig:subim2}
    \end{subfigure}
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.6]{figs/solutions/cache_solution.png}
        \caption{Shared cache synchronization}
        \label{fig:subim3}
    \end{subfigure}
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.6]{figs/solutions/message_broker_solution.png}
        \caption{Message broker sequentializing}
        \label{fig:subim4}
    \end{subfigure}
    \captionsetup{justification=centering,margin=1cm}
    \caption{\label{fig:knng} Existing synchronization approaches for multiple server applications}
\end{figure}

CodePudding user response:

Use \hspace and \vspace between the subfigures.

\documentclass{article}

\usepackage{subcaption}
\usepackage{graphicx}

\begin{document}

\begin{figure}[h]
    \centering
    \begin{subfigure}{0.4\textwidth}
        \centering
        \includegraphics[scale=0.6]{placeholder_1.png}
        \caption{Transaction level isolation}
        \label{fig:subim1}
    \end{subfigure}%
    \hspace{3em}%
    \vspace{1em}
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.6]{placeholder_1.png}
        \caption{Record locking}
        \label{fig:subim2}
    \end{subfigure}%
    \vspace{1em}
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.6]{placeholder_1.png}
        \caption{Shared cache synchronization}
        \label{fig:subim3}
    \end{subfigure}%
    \hspace{3em}%
    \begin{subfigure}[b]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.6]{placeholder_1.png}
        \caption{Message broker sequentializing}
        \label{fig:subim4}
    \end{subfigure}
    \captionsetup{justification=centering,margin=1cm}
    \caption{\label{fig:knng} Existing synchronization approaches for multiple server applications}
\end{figure}

\end{document}

space in subfigure


CodePudding user response:

Depending on what you want, you can have either images sticking to margins on both sides with some space in the middle or have them uniformly distributed over page. In both cases use \hspace{\hfill} in the middle as a filler. The former case does not require anything else. However, in the latter case, you would also need to add \hspace{\hfill} at both sides; this is the case in the example.

I also use a custom length since images seem to have the same size so you wouldn't need to repeat yourself each time you make a change.

Unfortunately, I can't post images this time.

The code

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup{format=hang}   % <--- added
\usepackage{showframe}       % Draws frames around a page
    \renewcommand*{\ShowFrameLinethickness}{0.2pt}
    \renewcommand*{\ShowFrameColor}{\color{blue}}
\newlength\sfigwidth


\begin{document}
\setlength\sfigwidth{0.37\textwidth}

\begin{figure}[h]
  \hspace{\fill}%   % <--- cases uniform redistribution
  \begin{subfigure}[t]{\sfigwidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{Transaction level isolation -- extra wording for demo}
    \label{fig:subim1}
  \end{subfigure}%
  \hspace{\fill}%
  \begin{subfigure}[t]{\sfigwidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{Record locking}
    \label{fig:subim2}
  \end{subfigure}%
  \hspace{\fill}   % <--- cases uniform redistribution

  \vspace{3ex}

  \hspace{\fill}%
  \begin{subfigure}[t]{\sfigwidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{Shared cache synchronization}
    \label{fig:subim3}
  \end{subfigure}%
  \hspace{\fill}%
  \begin{subfigure}[t]{\sfigwidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{Message broker sequentializing}
    \label{fig:subim4}
  \end{subfigure}%
  \hspace{\fill}
  
  \captionsetup{justification=centering,margin=1cm}
  \caption{\label{fig:knng} Existing synchronization approaches for multiple server applications}
\end{figure}
\end{document}
  • Related