将所有图像修剪至参考高度 (\textheight)

将所有图像修剪至参考高度 (\textheight)

我有一系列形状不相同的图像。我想从下方填充(负修剪)图像,使它们都具有相同的形状。我该怎么做?这是我的 MWE

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{float}
\usepackage{subfig}
\usepackage{tikz}% loads graphicx
\usepackage{graphicx,xcolor}

\begin{document}

\makeatletter
\newcommand{\definetrim}[2]{%
  \define@key{Gin}{#1}[]{\setkeys{Gin}{trim=#2,clip}}%
}
\makeatother

\definetrim{kit_mocap}{0 0 0 3cm} % {left bottom right top}
%\def\barheight{0.015}
\def\imagewidth{0.12\textwidth}
\def\imagehspace{\hspace{-0.25em}}

\NewDocumentCommand{\frameincludegraphicsred}{O{}m}{%
  \begingroup
  \sbox{0}{\includegraphics[#1]{#2}}%
  \setlength{\fboxrule}{0.3mm}% exaggerated to better see the effect
  \setlength{\fboxsep}{-\fboxrule}%
  \makebox[0pt][l]{\usebox{0}}%
  \textcolor{red}{\fbox{\rule{0pt}{\ht0}\rule{\wd0}{0pt}}}%
  \endgroup
}
\NewDocumentCommand{\frameincludegraphicsblue}{O{}m}{%
  \begingroup
  \sbox{0}{\includegraphics[#1]{#2}}%
  \setlength{\fboxrule}{0.3mm}% exaggerated to better see the effect
  \setlength{\fboxsep}{-\fboxrule}%
  \makebox[0pt][l]{\usebox{0}}%
  \textcolor{blue}{\fbox{\rule{0pt}{\ht0}\rule{\wd0}{0pt}}}%
  \endgroup
}
\NewDocumentCommand{\frameincludegraphicsblack}{O{}m}{%
  \begingroup
  \sbox{0}{\includegraphics[#1]{#2}}%
  \setlength{\fboxrule}{0.1mm}% exaggerated to better see the effect
  \setlength{\fboxsep}{-\fboxrule}%
  \makebox[0pt][l]{\usebox{0}}%
  \textcolor{black}{\fbox{\rule{0pt}{\ht0}\rule{\wd0}{0pt}}}%
  \endgroup
}

\begin{figure*}[ht]
\centering
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (image) at (0,0) {\frameincludegraphicsblue[width=\imagewidth,kit_mocap]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {Pred};
    \end{scope}
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (imageb) at (0,0) {\frameincludegraphicsblue[width=\imagewidth,clip]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {True};
    \end{scope}
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (image) at (0,0) {\frameincludegraphicsblue[width=\imagewidth,clip]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {Pred};
    \end{scope}
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (imaged) at (0,0) {\frameincludegraphicsblue[width=\imagewidth,clip]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {True};
    \end{scope}
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (image) at (0,0) {\frameincludegraphicsred[width=\imagewidth,clip]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {Pred};
    \end{scope}
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (image6) at (0,0) {\frameincludegraphicsred[width=\imagewidth,clip]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {True};
    \end{scope}
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (image) at (0,0) {\frameincludegraphicsred[width=\imagewidth,clip]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {Pred};
    \end{scope}
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (image) at (0,0) {\frameincludegraphicsred[width=\imagewidth,clip]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {True};
    \end{scope}
\end{tikzpicture}}

\end{figure*}

\end{document}

下面是我尝试的片段。我定义了一个变量,referenceheight0.08\textheight是 的高度版本\textwidth。0.08,因为 1/12 > 0.08,我有 12 个数字。然后我只是对图像进行负填充。它不起作用。

\def\referenceheight{0.08\textheight}
\begin{tikzpicture}[remember picture]
    \node[anchor=south east,inner sep=0] (image) at (0,0) {\frameincludegraphicsblue[width=\imagewidth,pad=0 -\referenceheight 0 0,clip]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \node[anchor=south east,draw,fill=white] at (0,0) {Pred};
    \end{scope}
\end{tikzpicture}}

在此处输入图片描述

在此处输入图片描述

答案1

只是一个想法。您可以将图像包含到equal size grouptcolorboxes 中,然后让该tcolorbox包为您完成工作。

\documentclass{article}
\usepackage[most]{tcolorbox}

\tcbset{ size=tight, width=3cm, nobeforeafter, equal height group, halign=center}

\begin{document}
\begin{tcolorbox}
\includegraphics[height=2cm]{example-image-A}
\end{tcolorbox}%
\begin{tcolorbox}
\includegraphics[height=1cm]{example-image-B}
\end{tcolorbox}%
\begin{tcolorbox}
\includegraphics[height=1.7cm]{example-image-c}
\end{tcolorbox}
\end{document}

在此处输入图片描述

相关内容