读取图形尺寸

读取图形尺寸

caption我使用和包将图形集(即图形和图表)按行对齐subcaption。由于图形和图表的长宽比不同,因此行中的标题未对齐(对象及其标题对齐到中间)

梅威瑟:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\graphicspath{{img/}{img/png/}}
\usepackage{float,multicol,pdflscape}
\usepackage{amsmath,amssymb,gensymb}

\usepackage{caption,subcaption}
\addto\captionsenglish{\renewcommand{\figurename}{Fig}}
\addto\captionsenglish{\renewcommand{\tablename}{Tab}}

\begin}{document}
\begin{figure}[H]\centering
\begin{subfigure}{.3\textwidth} % to have 3 figures on the line
\includegraphics[width=\textwidth]{fig1-1}
\caption{~}\label{fig1-1}
\end{subfigure}
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{fig1-2}
\caption{~}\label{fig1-2}
\end{subfigure}
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{graph1}
\caption{~}\label{graph1}
\end{subfigure}
%
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{fig2-1}
\caption{}\label{fig2-1}
\end{subfigure}
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{fig2-2}
\caption{}\label{fig2-2}
\end{subfigure}
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{graph2}
\caption{}\label{graph2}
\end{subfigure}
%
\caption{Caption.}
\end{figure}
\end{document}

例如,我怎样才能读取的高度fig1-1才能将其传递给\rule{0pt}{<height-of-fig1-1>},或者有(更)优雅的方式使其“美观”(最终结果是图形/图表对齐到中间,标题对齐到顶部)?

答案1

这似乎可以实现您想要的效果,除非您希望在子标题中添加文本。

\documentclass[a4paper]{article}
\usepackage{graphicx}

\usepackage{caption,subcaption}

\newcommand{\figurerow}[6]{%
  \sbox{0}{\includegraphics[width=.3\textwidth]{#1}}%
  \sbox{2}{\includegraphics[width=.3\textwidth]{#3}}%
  \sbox{4}{\includegraphics[width=.3\textwidth]{#5}}%
  \dimen0=\ht0
  \ifdim\ht2>\dimen0 \dimen0=\ht2 \fi
  \ifdim\ht4>\dimen0 \dimen0=\ht4 \fi
  \advance\dimen0\abovecaptionskip
  \advance\dimen0\baselineskip
  \figurerowfigure{0}{#2}
  \figurerowfigure{2}{#4}
  \figurerowfigure{4}{#6}\par
}
\newcommand{\figurerowfigure}[2]{%
  \begin{subfigure}[b][\dimen0][s]{.3\textwidth}
  \vfill
  \box#1
  \vfill
  \caption{}\label{#2}
  \end{subfigure}%
}

\begin{document}
\begin{figure}
\centering
\figurerow
  {example-image.pdf}{label1}
  {example-image-golden.pdf}{label2}
  {example-image-golden-upright.pdf}{label3}

\bigskip

\figurerow
  {example-image-golden.pdf}{label4}
  {example-image-golden-upright.pdf}{label5}
  {example-image.pdf}{label6}

\caption{Caption.}
\end{figure}
\end{document}

在此处输入图片描述

相关内容