0

How do you move a caption of a "figure" inside a minipage? I want the caption to be directly under the figure as illustrated in the picture. Thanks in advance!

\begin{figure} 
\centering
\hspace{0pt}
\begin{minipage}[t]{0.5\textwidth}
\centering
\vspace{14pt}
\begin{figure}

\includegraphics[scale=1.0]{99_stuff/figures/matplotlib/cyc2/linechart_Duration_cyc3.eps} %\vspace{-14pt} \captionof{figure}{Line chart duration \gls{gs} solver} \end{figure} %\caption{Line chart duration \gls{gs} solver}

\end{minipage} \hfill
\begin{minipage}[t]{.425\textwidth} \centering \vspace{0pt} \captionof{table}{Duration \gls{gs} solver} \begin{tabular}{c c c c} % centered columns (4 columns) \hline\hline %inserts double horizontal lines $N_{HO}$ & $hfov$ & $\sum v_{i,k,h}$ & $D_{GS}$ \ [0.5ex] % inserts table %heading \hline % inserts single horizontal line 1 & 360° & 195000 & 90.63 s \ % inserting body of the table 2 & 180° & 390000 & 96.45 s \ 3 & 120° & 585000 & 104.27 s \ 4 & 90° & 780000 & 111.47 s \ 5 & 72° & 975000 & 120.15 s \ 6 & 60° & 1170000 & 128.42 s \ 7 & $ \approx $ 51° & 1365000 & 134.09 s \ 8 & 45° & 1560000 & 142.21 s \ 9 & 40° & 1755000 & 151.09 s \ 10 & 36° & 1950000 & 158.38 s \ [1ex] % [1ex] adds vertical space \hline %inserts single line \end{tabular} \label{tab:timegs} % is used to refer this table in the text \end{minipage} \end{figure}

enter image description here

  • Welcome to TeX:SE! Your question seems to be duplicate to https://tex.stackexchange.com/questions/424121/placing-a-tikz-picture-and-table-side-by-side/424130#424130. See if this answer can help you. – Zarko Dec 08 '21 at 17:06

2 Answers2

1

With some code simplifications the caption will go below the figure as it should. The minipages are bottom aligned [b].

a

\documentclass[12pt,a4paper]{article}

\usepackage{graphicx}

\usepackage{caption} \usepackage[labelfont=bf, textfont=it]{caption}

\begin{document}

    \begin{minipage}[b]{0.5\textwidth}
        \centering  
        \includegraphics[width=\linewidth]{example-image}
        \captionof{figure}{Line chart duration GS solver}           
    \end{minipage}
    \hfill  
    \begin{minipage}[b]{.425\textwidth}
        \centering
        \captionof{table}{Duration GS  solver}
        \renewcommand{\arraystretch}{1.1}% added expand the cells
        \begin{tabular}{c c c c} % centered columns (4 columns)
            \hline\hline %inserts double horizontal lines
            $N_{HO}$ & $hfov$ & $\sum v_{i,k,h}$ & $D_{GS}$ \\ [0.5ex] % inserts table
            %heading
            \hline % inserts single horizontal line
            1 & 360° & 195000 & 90.63 s \\ % inserting body of the table
            2 & 180° & 390000 & 96.45 s \\
            3 & 120° & 585000 & 104.27 s \\
            4 & 90° & 780000 & 111.47 s \\
            5 & 72° & 975000 & 120.15 s \\
            6 & 60° & 1170000 & 128.42 s \\
            7 & $ \approx $ 51° & 1365000 & 134.09 s \\
            8 & 45° & 1560000 & 142.21 s \\
            9 & 40° & 1755000 & 151.09 s \\
            10 & 36° & 1950000 & 158.38 s \\

% [1ex] % [1ex] adds vertical space \hline %inserts single line \end{tabular} \label{tab:timegs} % is used to refer this table in the text \end{minipage}

\end{document}

Simon Dispa
  • 39,141
0

First, this fixes a few mistakes in your code (like putting a figure inside a figure). Note that the [t] option of minipage aligns the first baseline, which is the bottom of the image. Also, your tabular is larger than 0.5\textwidth.

Now if you want to align the caption with only part of the image, you will first need to measure the distance inside your image, then put the caption inside another smaller minipage.

\documentclass{article}
\usepackage{caption}
\usepackage{graphicx}
%\usepackage{glossaries}

\begin{document} \begin{figure} % first, measure width of tabular \sbox0{\strut \begin{tabular}{c c c c} % centered columns (4 columns) \hline\hline %inserts double horizontal lines $N_{HO}$ & $hfov$ & $\sum v_{i,k,h}$ & $D_{GS}$ \ [0.5ex] % inserts table %heading \hline % inserts single horizontal line 1 & 360° & 195000 & 90.63 s \ % inserting body of the table 2 & 180° & 390000 & 96.45 s \ 3 & 120° & 585000 & 104.27 s \ 4 & 90° & 780000 & 111.47 s \ 5 & 72° & 975000 & 120.15 s \ 6 & 60° & 1170000 & 128.42 s \ 7 & $ \approx $ 51° & 1365000 & 134.09 s \ 8 & 45° & 1560000 & 142.21 s \ 9 & 40° & 1755000 & 151.09 s \ 10 & 36° & 1950000 & 158.38 s \ [1ex] % [1ex] adds vertical space \hline %inserts single line \end{tabular}\strut} % \raisebox{-\height}{% move baseline to top \begin{minipage}{\dimexpr \textwidth-\wd0-\columnsep} \centering \includegraphics[width=\linewidth]{example-image} \captionof{figure}{Line chart duration gs solver}% replaced \gls{gs} \end{minipage}} \hfill \raisebox{-\height}{% move baseline to top \begin{minipage}{\wd0} \centering \captionof{table}{Duration gs solver}% replaced \gls{gs} \label{tab:timegs} % is used to refer this table in the text \usebox0 \end{minipage}} \end{figure}

\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120