使用 tabularx 和 subfloats 對齊圖形

使用 tabularx 和 subfloats 對齊圖形

我想做的是在tabularxandsubfloats環境中對齊圖形。

基本上我想使用 5 個圖形顯示流程/工作流程,其中 1-3 個「連接」和 4+5 個。

這是我的程式碼:我嘗試了兩種不同的方法,但兩者都不是很好對齊:

\documentclass{report}
\usepackage{pifont}
\usepackage[svgnames, x11names]{xcolor}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}
\usepackage{tabularx}

\newcommand\bigleftArrow{\color{Tomato2}\rotatebox[origin=c]{180}{\scalebox{2.4}[3.6]{\ding{225}}}}
\newcommand\bigrightArrow{\color{Tomato2}\rotatebox[origin=c]{0}{\scalebox{2.4}[3.6]{\ding{225}}}}

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{figure} [h]
\begin{tabularx}{\textwidth}{@{}*{5}{>{\centering\arraybackslash}X}@{}}
  \subfloat[text 1]{
     \includegraphics[width=0.28\textwidth]
     {example-image-a}}
      &
      \bigleftArrow
      &
  \subfloat[text 2]{
     \includegraphics[width=0.28\textwidth]
     {example-image-b}}
      &
      \bigleftArrow
      &
  \subfloat[text 3 is longer as  the others text text text text text]{
     \includegraphics[width=0.28\textwidth]
     {example-image-c}}
     \\
  \subfloat[text 4]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}
       &
       &
       \bigrightArrow
       &
       &
  \subfloat[text 5]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}


\end{tabularx}
  \captionof{figure}[]{long text 1}
  \label{fig:merge}
\end{figure}





\begin{figure} [hb]
\begin{tabularx}{\textwidth}{X m{10pt} C{110pt} m{10pt} X}
\centering 
  \subfloat[text 1]{
     \includegraphics[width=0.28\textwidth]
     {example-image-a}}
      &
      \bigleftArrow
      &
  \subfloat[text 2]{
     \includegraphics[width=0.28\textwidth]
     {example-image-b}}
      &
      \bigleftArrow
      &
  \subfloat[text 3 is longer as  the others text text text text text]{
     \includegraphics[width=0.28\textwidth]
     {example-image-c}}
  \\ 
  \subfloat[text4]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}
      &
      &
      \bigrightArrow
      &
      &
  \subfloat[text5]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}


\end{tabularx} 
  \captionof{figure}[]{long text 2}

\end{figure}

\end{document}

問題是,我想讓箭頭在每行中垂直和水平居中。但這是我的結果:

在此輸入影像描述 在此輸入影像描述


它應該是這樣的:

在此輸入影像描述

有人可以給我有關對齊的提示(或者如果需要解決此問題,可以使用其他方法)嗎?

答案1

您可以使用 的一些組合\makebox

\vcenterobject宏垂直移動其參數,使高度等於深度。

\makebox[0pt]{...}指令會建立一個零寬度的框,位於「列」之間。

請注意,由於未受保護的行尾,您有幾個虛假空格。我還簡化了箭頭的定義。

\documentclass{report}
\usepackage{pifont}
\usepackage[svgnames, x11names]{xcolor}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}

\newcommand\bigleftArrow{%
  \scalebox{-2.4}[3.6]{%
    \color{Tomato2}\ding{225}%
  }%
}
\newcommand\bigrightArrow{%
  \scalebox{2.4}[3.6]{%
    \color{Tomato2}\ding{225}%
  }%
}

\newcommand{\vcenterobject}[1]{%
  \begin{tabular}{@{}c@{}}#1\end{tabular}%
}

\begin{document}

\begin{figure}[htp]

\makebox[.33333\textwidth]{%
  \subfloat[text 1]{%
    \vcenterobject{%
      \includegraphics[width=0.2\textwidth]{example-image-a}%
    }%
  }
}%
\hfill\makebox[0pt]{\vcenterobject{\bigleftArrow}}\hfill
\makebox[.33333\textwidth]{%
  \subfloat[text 2]{%
    \vcenterobject{%
      \includegraphics[width=0.2\textwidth]{example-image-b}%
    }%
  }%
}%
\hfill\makebox[0pt]{\vcenterobject{\bigleftArrow}}\hfill
\makebox[.33333\textwidth]{%
  \subfloat[text 3 is longer as  the others text text text text text]{%
    \vcenterobject{%
      \includegraphics[width=0.2\textwidth]{example-image-c}%
    }%
  }%
}

\makebox[.33333\textwidth]{%
  \subfloat[text 4]{%
    \vcenterobject{%
      \includegraphics[width=0.2\textwidth]{example-image}%
    }%
  }%
}%
\hfill\makebox[0pt]{\vcenterobject{\bigrightArrow}}\hfill
\makebox[.33333\textwidth]{%
  \subfloat[text 5]{%
    \vcenterobject{%
      \includegraphics[width=0.2\textwidth]{example-image}%
    }%
  }%
}

\caption{long text 1}\label{fig:merge}

\end{figure}

\end{document}

在此輸入影像描述

答案2

從 TeX 原始的角度來看,你需要做這樣的事情:

\def\vhb#1{\vtop{\hbox{#1}}}
\def\rb#1{\raise.9cm\hbox{#1}}

\begin{figure}[h]
\hbox to\hsize{%
  \vhb{\subfloat[text 1]{\includegraphics[width=0.28\textwidth]{example-image-a}}}%
  \hss \rb\bigleftArrow \hss
  \vhb{\subfloat[text 2]{\includegraphics[width=0.28\textwidth]{example-image-b}}}%
  \hss \rb\bigleftArrow \hss
  \vhb{\subfloat[text 3 is longer as  the others text text text text text]{
     \includegraphics[width=0.28\textwidth]{example-image-c}}}%
}
\hbox to\hsize{%
  \vhb{\subfloat[text 4]{\includegraphics[width=0.28\textwidth]{example-image}}}%
  \hss \rb\bigrightArrow \hss
  \vhb{\subfloat[text 5]{\includegraphics[width=0.28\textwidth]{example-image}}}%
}
\end{figure}

相關內容