填滿一列的儲存格而不是表格的所有儲存格

填滿一列的儲存格而不是表格的所有儲存格

我希望我的列單元格中只有一個具有頂部填充。我試過 :

\def\arraystretch{factor}%

但結果並不理想。因為我不希望所有列都有頂部填充。

是否有辦法為一列的儲存格指定頂部填充?

編輯

我有一個 10 行 4 列的長表,第 4 列有圖像。這是我的程式碼(總結為 3 列):

\begin{longtable}{|p{2cm}|p{3cm}|p{8cm}|p{2cm}|}
\caption{my caption}
\label{table:10.1}
\\
\hline

\centering titile 1     &  \centering title 2 & \centering title 3 &  {\centering  title 4}  \\
\hline \hline
first r first c &  first r second c &  first r third c & 
      \begin{minipage}{.12\textwidth}
      \includegraphics[width=\linewidth]{table10-1-1.png}
    \end{minipage}
 \\
\hline
second r first c & second r second c  &  second r third c & 
\begin{minipage}{.12\textwidth}
      \includegraphics[width=\linewidth]{table10-1-2.png}
    \end{minipage}
     \\
\hline
third r first c &  third r second d &  third r third c & 
\begin{minipage}{.12\textwidth}
      \includegraphics[width=\linewidth]{table10-1-3.png}
    \end{minipage} 

    \\
\hline
\end{longtable}

結果是這樣的:

在此輸入影像描述

我嘗試使用 {\renewcommand{\arraystretch}{4}% 進行填充,但結果不佳: 在此輸入影像描述

如果只有第四列的儲存格有填滿就可以了。

無論如何,我在這個表中還有另一個問題:

1- 單元格中的文字對齊,有時單字之間的間距太大。

我將感謝任何幫助。

答案1

由於您用於minipage圖像,因此可以在其中添加一些填充:

\documentclass{article}
\usepackage[margin=1cm]{geometry}% just for not having overfull lines
\usepackage{graphicx}
\usepackage{longtable,array}

\begin{document}
\begin{longtable}{|p{2cm}|p{3cm}|p{8cm}|p{2cm}|}
\caption{my caption}
\label{table:10.1}
\\
\hline

\centering title 1 &
  \centering title 2 &
  \centering title 3 &
  \centering\arraybackslash title 4 \\
\hline \hline
first r first c &  first r second c &  first r third c & 
  \begin{minipage}{\linewidth}
  \vspace{12pt}
  \includegraphics[width=\linewidth]{example-grid-100x100pt}\par
  \vspace{12pt}
  \end{minipage}
 \\
\hline
second r first c & second r second c  &  second r third c & 
  \begin{minipage}{\linewidth}
  \vspace{12pt}
  \includegraphics[width=\linewidth]{example-grid-100x100pt}\par
  \vspace{12pt}
  \end{minipage}
\\
\hline
third r first c &  third r second d &  third r third c & 
  \begin{minipage}{\linewidth}
  \vspace{12pt}
  \includegraphics[width=\linewidth]{example-grid-100x100pt}\par
  \vspace{3pt}
  \includegraphics[width=\linewidth]{example-grid-100x100pt}\par
  \vspace{12pt}
  \end{minipage}
\\
\hline
\end{longtable}
\end{document}

請注意,我指定的寬度minipage與它所在的列一樣寬p,圖片也是如此。

考慮到方案是固定的,輸入可能會被簡化。

在此輸入影像描述

透過小的更改,您可以將文字放在從頂部開始的前三列中。這裡我\vspace{0pt}在迷你頁的頂部使用

\documentclass{article}
\usepackage[margin=1cm]{geometry}% just for not having overfull lines
\usepackage{graphicx}
\usepackage{longtable,array}

\begin{document}
\begin{longtable}{|p{2cm}|p{3cm}|p{8cm}|p{2cm}|}
\caption{my caption}
\label{table:10.1}
\\
\hline

\centering title 1 &
  \centering title 2 &
  \centering title 3 &
  \centering\arraybackslash title 4 \\
\hline \hline
first r first c &  first r second c &  first r third c & 
  \begin{minipage}[t]{\linewidth}
  \vspace{0pt}
  \includegraphics[width=\linewidth]{example-grid-100x100pt}\par
  \vspace{12pt}
  \end{minipage}
 \\
\hline
second r first c & second r second c  &  second r third c & 
  \begin{minipage}[t]{\linewidth}
  \vspace{0pt}
  \includegraphics[width=\linewidth]{example-grid-100x100pt}\par
  \vspace{12pt}
  \end{minipage}
\\
\hline
third r first c &  third r second d &  third r third c & 
  \begin{minipage}[t]{\linewidth}
  \vspace{0pt}
  \includegraphics[width=\linewidth]{example-grid-100x100pt}\par
  \vspace{3pt}
  \includegraphics[width=\linewidth]{example-grid-100x100pt}\par
  \vspace{12pt}
  \end{minipage}
\\
\hline
\end{longtable}
\end{document}

在此輸入影像描述

相關內容