[Tex/LaTex] How to vertically and horizontally center a minipage

horizontal alignmentminipagevertical alignment

  1. I tried centering horizontally using the "adjustwidth" environment, but unfortunately, it's not very accurate. Also my captions are not centered under my figures anymore.

  2. I have no idea how to use the area above my minipage. I tried using vspace, but I can't seem to move the minipage upwards.

Following image illustrates my issue:

the problem

Following piece of code (MWE) shows what I tried to do:

\documentclass[11pt, a4paper, openright]{book} %oneside option
\usepackage{etex}
\usepackage{tocbibind}

%PACKAGES
%\usepackage{times}
\usepackage[dvips]{graphicx}
\usepackage{chngpage}
\usepackage{url}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[all]{xy}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{psfrag} %laprint
\usepackage{color}
\usepackage[usenames]{xcolor}
\usepackage[pdf,usenames,dvipsnames]{pstricks}
\usepackage{tikz}
\usepackage{auto-pst-pdf}
\usepackage{epsfig}
\usepackage{pst-grad} % For gradients
\usepackage{pst-plot} % For axes
\usepackage{epstopdf}
\usepackage{float}
\usepackage{pdfpages}
\usepackage{subfigure}
\usepackage{mathabx}
\usepackage[chapter]{algorithm}
\usepackage[small,bf,hang]{caption}
\renewcommand{\captionfont}{\small\itshape}
\usepackage{natbib}
\bibpunct{[}{]}{;}{n}{,}{,}     % Numerical system
\usepackage{listings}

%LAYOUT
\bibliographystyle{ieeetr}
\usepackage{chngcntr}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{1}

\setlength{\textheight}{237mm} %A4 - 297
\setlength{\textwidth}{160mm} %A4 - 210
\setlength{\topmargin}{-0.54cm} %A4
\setlength{\headheight}{15pt} %A4
\setlength{\oddsidemargin}{0.46cm}  %A4 Centers text.
\setlength{\evensidemargin}{-.54cm} %A4

%
%Left margin 30 mm, right margin 20 mm, top margin 20 mm, bottom     margin 20 mm.
%2,54

\usepackage{fancyhdr}
\pagestyle{fancy}

% with this we ensure that the chapter and section
% headings are in lowercase.
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ #1}}
\fancyhf{} % delete current header and footer


\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}

\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % space for the rule
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers on plain pages
\renewcommand{\headrulewidth}{0pt} % and the line
}

\parskip 6pt           % sets spacing between paragraphs
\parindent 0pt       % sets leading space for paragraphs 

\newtheorem{definition}{Definition}[chapter]

\newenvironment{remark}[1][Remark]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

\newcommand{\vectornorm}[1]{\|#1\|}

%Locally remove natural indent of itemize
\usepackage{enumitem}

\usepackage{hyperref}
\hypersetup{
    colorlinks,%
    citecolor=black,%
    filecolor=black,%
    linkcolor=black,%
    urlcolor=black
}

\begin{document}
\begin{figure}[p]
\makebox[\textwidth][c]{%
    \begin{minipage}[b]{0.565\linewidth}
        \centering
        \includegraphics[scale=0.7]{plots/Reflex_128_Plot_xRemovals_yCPUsecondsEncoding.eps} 
        \caption{Reflex: $128 \times 128$ - Encoder} 
        \label{plot:encoding_decoding_cpu_time_2a} 
    \end{minipage}%
    \begin{minipage}[b]{0.565\linewidth}
        \centering
        \includegraphics[scale=0.7]{plots/Reflex_128_Plot_xRemovals_yCPUsecondsDecoding.eps} 
        \caption{Reflex: $128 \times 128$ - Decoder}
        \label{plot:encoding_decoding_cpu_time_2b}  
    \end{minipage}}%

    \makebox[\textwidth][c]{%       
    \begin{minipage}[b]{0.565\linewidth}
        \centering
        \includegraphics[scale=0.7]{plots/Lena_128_Plot_xRemovals_yCPUsecondsEncoding.eps} 
        \caption{Lena: $128 \times 128$ - Encoder} 
        \label{plot:encoding_decoding_cpu_time_3a} 
    \end{minipage}%
    \begin{minipage}[b]{0.565\linewidth}
        \centering
        \includegraphics[scale=0.7]{plots/Lena_128_Plot_xRemovals_yCPUsecondsDecoding.eps} 
        \caption{Lena: $128 \times 128$ - Decoder} 
        \label{plot:encoding_decoding_cpu_time_3b} 
    \end{minipage}}%

    \makebox[\textwidth][c]{%
    \begin{minipage}[b]{0.565\linewidth}
        \centering
        \includegraphics[scale=0.7]{plots/Fruits_128_Plot_xRemovals_yCPUsecondsEncoding.eps} 
        \caption{Fruits: $128 \times 128$ - Encoder} 
        \label{plot:encoding_decoding_cpu_time_4a} 
    \end{minipage}%
    \begin{minipage}[b]{0.565\linewidth}
        \includegraphics[scale=0.7]{plots/Fruits_128_Plot_xRemovals_yCPUsecondsDecoding.eps}
        \centering 
        \caption{Fruits: $128 \times 128$ - Decoder}
        \label{plot:encoding_decoding_cpu_time_4b}  
    \end{minipage}}%
\end{figure}
\end{document}

Thanks in advance for your help!

Best Answer

As your minipages are bigger than half of the page, they will need some more place on both sides of the text. Just put every two minipages in a \makebox for this. (Not my recommendation. Try to fit everything in your margins as this will look more consistent over your whole report.)

For vertical centring, just use the [p] specifier of your figure. If you use [t] instead or none at all, it will be flushed to the top if followed by text. No need for \vspace.

Load caption in order to get better spacing between captions and following images.

% arara: pdflatex

\documentclass{article}
\usepackage[demo]{graphicx}
%\usepackage{changepage} % not needed any more
\usepackage{showframe} % just for demo
\usepackage{caption}

\begin{document}
\begin{figure}[p]
    \makebox[\textwidth][c]{%
        \begin{minipage}[b]{0.565\linewidth}
            \centering
            \includegraphics[scale=0.7]{plots/Reflex_128_Plot_xRemovals_yCPUsecondsEncoding.eps} 
            \caption{Reflex: $128 \times 128$ - Encoder} 
            \label{plot:encoding_decoding_cpu_time_2a} 
        \end{minipage}%
        \begin{minipage}[b]{0.565\linewidth}
            \centering
            \includegraphics[scale=0.7]{plots/Reflex_128_Plot_xRemovals_yCPUsecondsDecoding.eps} 
            \caption{Reflex: $128 \times 128$ - Decoder}
            \label{plot:encoding_decoding_cpu_time_2b}  
        \end{minipage}}%

        \makebox[\textwidth][c]{%       
        \begin{minipage}[b]{0.565\linewidth}
            \centering
            \includegraphics[scale=0.7]{plots/Lena_128_Plot_xRemovals_yCPUsecondsEncoding.eps} 
            \caption{Lena: $128 \times 128$ - Encoder} 
            \label{plot:encoding_decoding_cpu_time_3a} 
        \end{minipage}%
        \begin{minipage}[b]{0.565\linewidth}
            \centering
            \includegraphics[scale=0.7]{plots/Lena_128_Plot_xRemovals_yCPUsecondsDecoding.eps} 
            \caption{Lena: $128 \times 128$ - Decoder} 
            \label{plot:encoding_decoding_cpu_time_3b} 
        \end{minipage}}%

        \makebox[\textwidth][c]{%
        \begin{minipage}[b]{0.565\linewidth}
            \centering
            \includegraphics[scale=0.7]{plots/Fruits_128_Plot_xRemovals_yCPUsecondsEncoding.eps} 
            \caption{Fruits: $128 \times 128$ - Encoder} 
            \label{plot:encoding_decoding_cpu_time_4a} 
        \end{minipage}%
        \begin{minipage}[b]{0.565\linewidth}
            \includegraphics[scale=0.7]{plots/Fruits_128_Plot_xRemovals_yCPUsecondsDecoding.eps}
            \centering 
            \caption{Fruits: $128 \times 128$ - Decoder}
            \label{plot:encoding_decoding_cpu_time_4b}  
        \end{minipage}}%
\end{figure}
\end{document}

enter image description here