初始问题(已解决)

初始问题(已解决)

初始问题(已解决)

有一些表格。在我添加一些图片之前,一切都很好。添加图片后,子列中的文本不再水平居中,垂直线也不会延伸。我还希望每个单元格中的文本都居中(而不是左居中),并且包含图片的单元格中没有填充或填充相同,以使其看起来正确。

代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage{graphicx}
\usepackage{multirow}

\usepackage[letterpaper, landscape, margin=5mm]{geometry}
\title{}

\begin{document}

\section{Some table}

\begin{table}[h]
\center
\resizebox{26cm}{!}{
\begin{tabular}{|@{}c@{}|@{}c@{}|c|p{4cm}}
\hline
    \begin{tabular}{p{1cm}|p{1.5cm}|p{1.8cm}|p{1cm}}
    \multicolumn{4}{c}{Col1} \\ \hline
    subcol1 & subcol2 & subcol3 & subcol4\\ 
    \end{tabular}
    & 
    \begin{tabular}{p{1cm}|p{1cm}|p{1cm}|p{1cm}}
    \multicolumn{4}{c}{Col2} \\ \hline
   subcol5 & subcol6 & subcol7 & subcol8\\ 
    \end{tabular} & Col3 & Figures \\ \hline

    \begin{tabular}{@{}p{1cm}|p{1.5cm}|p{1.8cm}|p{1cm}@{}}
   text & text & text & text 
    \end{tabular}

    &
    \begin{tabular}{@{}p{1cm}|p{1cm}|p{1cm}|p{1cm}@{}}
    text  &   text   &   text   & text
    \end{tabular} & text &

    \includegraphics[width=\linewidth]{sheep.jpg}

    \\ \hline

\end{tabular}
}
\label{tab:my_label}
\end{table}
\end{document}

编辑:

现在添加 Col0 时出现问题,如下图所示。它与 Subcol1 共享单元格。

在此处输入图片描述

代码2:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage{graphicx}
\usepackage[export]{adjustbox}% added
\usepackage{multirow, tabularx}

\usepackage[letterpaper, landscape, margin=5mm]{geometry}
\title{}

\begin{document}

\section{Some table}

\begin{table}[h]
\centering
\begin{tabularx}{\linewidth}
            {|X|>{\hsize=0.7\hsize}X|X|>{\hsize=1.3\hsize}X|X
             |X|X|X|X
             |X|p{4cm}|}  % added |X| for Col0
    \hline

    \multirow{2}{*}{Col0} & % wanted to fill it with Col0 text

    \multicolumn{4}{|c|}{Col1} & \multicolumn{4}{c|}{Col2} & 
    \multirow{2}{*}{Col3}   &   \multirow{2}{*}{Figures}                          \\

    \cline{2-9}
subcol1 & subcol2 & subcol3 & subcol4 & subcol5 & subcol6 & subcol7 & subcol8 &   \\
    \hline
  text & text & text    & text    & text    & text    &   text  &  text   & text    & text 
        &   \includegraphics[width=\linewidth, 
                             margin=0pt \tabcolsep, 
                             valign=m]              
                             {example-image-a}           \\
   \hline
\end{tabularx}
\label{tab:my_label}
\end{table}
\end{document}

答案1

像这样?

在此处输入图片描述

  • 添加了用于图像垂直居中的包adjustbox并在图像上方和下方添加垂直空白
  • 删除了子表,现在只使用一个(主)表

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage{graphicx}
\usepackage[export]{adjustbox}% added
\usepackage{multirow}

\usepackage[letterpaper, landscape, margin=5mm]{geometry}
\title{}

\begin{document}

\section{Some table}

\begin{table}[h]
\centering
\resizebox{26cm}{!}{
\begin{tabular}{|p{1cm}|p{1.5cm}|p{1.8cm}|p{1cm}
                | p{1cm}|p{1cm}|p{1cm}|p{1cm}
                | p{1cm}|p{1.5cm}|p{1.8cm}|p{1cm}|p{4cm}|}% changed
    \hline
\multicolumn{4}{|c}{Col1} & \multicolumn{4}{|c|}{Col2} & 
    \multirow{2}{*}{Col3}   &   \multirow{2}{*}{Figures}                           \\
    \cline{1-8}
subcol1 & subcol2 & subcol3 & subcol4 & subcol5 & subcol6 & subcol7 & subcol8 & &   \\
    \hline
   text & text    & text    & text    & text    &   text  &  text   & text    & text 
        &   \includegraphics[width=\linewidth, 
                             margin=0pt \tabcolsep, % added
                             valign=m]              % added
                             {example-image-a}           \\
   \hline
\end{tabular}
}
\label{tab:my_label}
\end{table}
\end{document}

使用\resizebox{...}可能会带来意想不到的麻烦。更好的方法是在调整表格大小后确定列宽。例如使用\tabularx

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage{graphicx}
\usepackage[export]{adjustbox}% added
\usepackage{multirow, tabularx}

\usepackage[letterpaper, landscape, margin=5mm]{geometry}
\title{}

\begin{document}

\section{Some table}

\begin{table}[h]
\centering
\begin{tabularx}{\linewidth}
            {|>{\hsize=0.7\hsize}X|X|>{\hsize=1.3\hsize}X|X
             |X|X|X|X
             |X|p{4cm}|}% changed
    \hline
\multicolumn{4}{|c|}{Col1} & \multicolumn{4}{c|}{Col2} & 
    \multirow{2}{*}{Col3}   &   \multirow{2}{*}{Figures}                           \\
    \cline{1-8}
subcol1 & subcol2 & subcol3 & subcol4 & subcol5 & subcol6 & subcol7 & subcol8 & &   \\
    \hline
   text & text    & text    & text    & text    &   text  &  text   & text    & text 
        &   \includegraphics[width=\linewidth, 
                             margin=0pt \tabcolsep, % added
                             valign=m]              % added
                             {example-image-a}           \\
   \hline
\end{tabularx}
\label{tab:my_label}
\end{table}
\end{document}

附录:

关于你对方程的编辑:通过添加新列,你应该充分纠正

  • \cline(表格中新的列数),
  • \multicolumn{4}{|c|}{...}\multicolumn{4}{c|}{...}
  • 特别注意声明的列数与表中使用的列数相等。如果它们不相等,即表中使用的列数较少,那么就会发生不匹配的情况,就像您遇到的那样。

新表的正确代码是:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lscape}
\usepackage{graphicx}
\usepackage[export]{adjustbox}% added
\usepackage{multirow, tabularx}

\usepackage[letterpaper, landscape, margin=5mm]{geometry}
\title{}

\begin{document}

\section{Some table}

\begin{table}[h]
\centering
\begin{tabularx}{\linewidth}
            {|X
             |>{\hsize=0.7\hsize}X|X|>{\hsize=1.3\hsize}X|X
             |X|X|X|X
             |X|p{4cm}|}  % added |X| for Col0
    \hline
Col0 & % wanted to fill it with Col0 text
    \multicolumn{4}{c|}{Col1} & \multicolumn{4}{c|}{Col2} &
    \multirow{2}{*}{Col3}   &   \multirow{2}{*}{Figures}                                 \\
    \cline{1-9} % corrected number of spaned columns
subcol1 & subcol2 & subcol3 & subcol4 & subcol5 & subcol6 & subcol7 & subcol8 
        &         &         &                                               \\ % corrected number of ampersands
    \hline
  text  & text    & text    & text    & text    & text    &   text  &  text   
        & text    & text    &   \includegraphics[width=\linewidth,
                                                 margin=0pt \tabcolsep,
                                                 valign=m]
                                                 {example-image-a}           \\
   \hline
\end{tabularx}
\label{tab:my_label}
\end{table}
\end{document}

在此处输入图片描述

附录(2):如果我正确理解了您下面的评论,您希望获得以下内容:

在此处输入图片描述

为此,对上述附录中的示例做了两处小的改动:

  • 第一个单元格现在是multirow单元格
  • cline现在不考虑第一列

\begin{table}[h]
\centering
\begin{tabularx}{\linewidth}
            {|X
             |>{\hsize=0.7\hsize}X|X|>{\hsize=1.3\hsize}X|X
             |X|X|X|X
             |X|p{4cm}|}  % added |X| for Col0
    \hline
\multirow{2}{=}{Col0} & % wanted to fill it with Col0 text
    \multicolumn{4}{c|}{Col1} & \multicolumn{4}{c|}{Col2} &
    \multirow{2}{=}{Col3}   &   \multirow{2}{=}{Figures}                                 \\
    \cline{2-9} % corrected number of spanned columns
        & subcol2 & subcol3 & subcol4 & subcol5 & subcol6 & subcol7 & subcol8
        &         &         &                                               \\ % corrected number of ampersands
    \hline
  text  & text    & text    & text    & text    & text    &   text  &  text
        & text    & text    &   \includegraphics[width=\linewidth,
                                                 margin=0pt \tabcolsep,
                                                 valign=m]
                                                 {example-image-a}           \\
   \hline
\end{tabularx}
\label{tab:my_label}
\end{table}

注意:在上面的代码片段中,您可以将其与第一个附录中的这部分代码进行比较,发现 的选项也发生了变化multirow。从\multirow{2}{*}{...}\multirow{2}{=}{...}。如果您安装了最新版本的 omultirow软件包,此更改将起作用。请将{=}其告知multirow,其中考虑在 中确定的列格式\begin{tabularx}{\linewidth}{...}

相关内容