如何将标题移到图表下方?迷你页面由相邻的图表和表格组成

如何将标题移到图表下方?迷你页面由相邻的图表和表格组成

如何在小页面内移动“图形”的标题?我希望标题位于图形正下方,如图所示。提前致谢!

\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}

在此处输入图片描述

答案1

通过一些代码简化,标题将如其所愿地位于图形下方。小页面底部对齐[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}

答案2

首先,这修复了代码中的几个错误(例如将一个图形放在另一个图形中)。请注意,minipage 的 [t] 选项会对齐第一个基线,即图像的底部。此外,您的表格大于0.5\textwidth

现在,如果您只想将标题与图像的一部分对齐,则首先需要测量图像内的距离,然后将标题放在另一个较小的页面内。

\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}

演示

相关内容