创建一个单元格内有多个列的 LaTeX 表

创建一个单元格内有多个列的 LaTeX 表

我正在尝试复制在此网页

在此处输入图片描述

我正在尝试让多个单元格出现在第二个表格列的单元格中。该怎么做?我尝试使用该multirow包。

梅威瑟:

\documentclass{article}
\usepackage{longtable}
\usepackage{multirow}
\usepackage[table]{xcolor}
\begin{document}

\begin{longtable}{|p{3cm}|p{6cm}|p{5cm}|}
\hline
\rowcolor[HTML]{000000}
\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{Object}}}
    &\multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{Details}}}
    & \multicolumn{1}{|c|}{\cellcolor[HTML]{000000}{\color[HTML]{FFFFFF} \textbf{Notes}}} \\ \hline
 NAME & \multicolumn{2}{c|}{test} {DATE} \\ {Time (UTC): 22:59:41-23:22:48} \\
                {Filter/s used: I, R, B, V} \\ {Telescope/s used: TELESCOPE}
    & A total of 20 exposures all taken with an exposure length of 60.0 seconds. \\ \hline
\end{longtable}

\end{document}

答案1

只要您的目标只是重现表格,您的问题就与多行无关。您的表格有 4 列,您只需使用 \cline{c1-c2} 放置部分水平线。

但是,如果您想填充文件中的单元格而不是手动填充,则可能必须使用多行。

\documentclass{article}

\usepackage[width=20cm]{geometry}

\usepackage{longtable}
\usepackage[table]{xcolor}

\newcommand\doublestrut{\vrule width 0pt height 2\ht\strutbox depth 2\dp\strutbox}

\begin{document}
\footnotesize
\begin{tabular}{|p{3cm}|p{2.4cm}|p{2.4cm}|p{10cm}|}\hline
\rowcolor{black}
\multicolumn{1}{|c|}{\doublestrut\color{white}\textbf{Index}}  &
    \multicolumn{2}{c|}{\color{white}\textbf{Details}}         &
    \multicolumn{1}{c|}{\color{white}\textbf{Notes}}\\\hline
\hfil Object & Date       & Time                    & \\
             &            &                         & \\\cline{2-3}
             & Eye Pierce & Seeing                  & \\
             &            &                         & \\\cline{2-3}
             & \multicolumn{2}{l|}{Instrument Type} & \\
             & \multicolumn{2}{l|}{}                & \\\hline
\hfil Object & Date       & Time                    & \\
             &            &                         & \\\cline{2-3}
             & Eye Pierce & Seeing                  & \\
             &            &                         & \\\cline{2-3}
             & \multicolumn{2}{l|}{Instrument Type} & \\
             & \multicolumn{2}{l|}{}                & \\\hline
\end{tabular}
\end{document}

在此处输入图片描述

答案2

这里有一个解决方案\multirow,即长桌头部的设置以及您的图像和 mwe 线条(参见评论):

\documentclass{article}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3.5cm,lmargin=2cm,rmargin=2cm,marginparwidth=1cm}% Set these parameters according to your need 

\usepackage{longtable}
\usepackage{makecell} 
\usepackage{multirow}
\usepackage[table]{xcolor}
\renewcommand*{\arraystretch}{1.3}
\newcommand{\whitebf}[1]{\textcolor{white}{\textbf{#1}}}
%\usepackage{showframe}% Uncomment this to see the frame of your document, it is usefull to avoid going out of the borders

\begin{document}
\centering
\begin{longtable}{|p{3cm}|p{3cm}|p{3cm}|p{5cm}|}
    \rowcolor{black}
    \makecell[c]{\whitebf{Object}} &
    \multicolumn{2}{c}{\whitebf{Details}} & 
    \makecell[c]{\whitebf{Notes}} \\*
    \hline
    \endhead
    % Here I try to redo your MWE lines:
    \makecell[c]{Name} & Date & Time (UTC) & \multirow[t]{6}{5cm}{A total of 20 exposures all taken with an exposure length of 60.0 seconds.}\\*
    \multirow[t]{5}{3cm}{NAME has done this} & 17/11/2016 & 22:59:41-23:22:48 & \\*
    \cline{2-3}
     & Filter/s used & Something & \\* 
     & I, R, B, V & Quack & \\*
    \cline{2-3} 
     & \multicolumn{2}{l|}{Telescope/s used}  & \\*
     & \multicolumn{2}{l|}{TELESCOPE}  & \tabularnewline
    \hline 
    % Here I try to redo your image lines:
    \makecell[c]{Object} & Date & Time & \multirow[t]{6}{5cm}{ }\\*
    \multirow[t]{5}{3cm}{ } &  &  & \\*
    \cline{2-3}
     & Eye Pierce & Seeing &\\* 
     &  &  &\\*
    \cline{2-3} 
     & \multicolumn{2}{l|}{Instrument Type}  & \\*
     & \multicolumn{2}{l|}{ }  & \tabularnewline
    \hline
        % Here I try to redo your image lines:
    \makecell[c]{Object} & Date & Time & \multirow[t]{6}{5cm}{ }\\*
    \multirow[t]{5}{3cm}{ } &  &  & \\*
    \cline{2-3}
    & Eye Pierce & Seeing &\\* 
    &  &  &\\*
    \cline{2-3} 
    & \multicolumn{2}{l|}{Instrument Type}  & \\*
    & \multicolumn{2}{l|}{ }  & \tabularnewline
    \hline
        % Here I try to redo your image lines:
    \makecell[c]{Object} & Date & Time & \multirow[t]{6}{5cm}{ }\\*
    \multirow[t]{5}{3cm}{ } &  &  & \\*
    \cline{2-3}
    & Eye Pierce & Seeing &\\* 
    &  &  &\\*
    \cline{2-3} 
    & \multicolumn{2}{l|}{Instrument Type}  & \\*
    & \multicolumn{2}{l|}{ }  & \tabularnewline
    \hline
        % Here I try to redo your image lines:
    \makecell[c]{Object} & Date & Time & \multirow[t]{6}{5cm}{ }\\*
    \multirow[t]{5}{3cm}{ } &  &  & \\*
    \cline{2-3}
    & Eye Pierce & Seeing &\\* 
    &  &  &\\*
    \cline{2-3} 
    & \multicolumn{2}{l|}{Instrument Type}  & \\*
    & \multicolumn{2}{l|}{ }  & \tabularnewline
    \hline
        % Here I try to redo your image lines:
    \makecell[c]{Object} & Date & Time & \multirow[t]{6}{5cm}{ }\\*
    \multirow[t]{5}{3cm}{ } &  &  & \\*
    \cline{2-3}
    & Eye Pierce & Seeing &\\* 
    &  &  &\\*
    \cline{2-3} 
    & \multicolumn{2}{l|}{Instrument Type}  & \\*
    & \multicolumn{2}{l|}{ }  & \tabularnewline
    \hline
    \newpage
    % Here I try to redo your image lines:
    \makecell[c]{Object} & Date & Time & \multirow[t]{6}{5cm}{ }\\*
    \multirow[t]{5}{3cm}{ } &  &  & \\*
    \cline{2-3}
    & Eye Pierce & Seeing &\\* 
    &  &  &\\*
    \cline{2-3} 
    & \multicolumn{2}{l|}{Instrument Type}  & \\*
    & \multicolumn{2}{l|}{ }  & \tabularnewline
    \hline
\end{longtable}
\end{document}

第一页:

第一页

第二页:

第二页

答案3

使用ltablex包和X包中的列类型的解决方案tabularx

\documentclass{article}
\usepackage[margin=30mm]{geometry}
\usepackage{ltablex,makecell,multirow}
    \renewcommand\thead{\color{white}\bfseries\normalsize}
\newlength\noteswidth
\setlength\noteswidth{5cm}% <-- width of the column wit notes
    \newcommand\mcp[1]{\multicolumn{2}% <-- calculation of multicolumn width
                        {p{\dimexpr0.66\linewidth-0.66\noteswidth-3\tabcolsep\relax}|}{#1}}
    \newcolumntype{C}{>{\centering\arraybackslash}X}% first column has centered content
\usepackage[table]{xcolor}

\begin{document}
{\renewcommand\arraystretch{1.2}% <-- more vertical space
\begin{tabularx}{\textwidth}{|C|X|X|p{\noteswidth}|}
\hline
\rowcolor[HTML]{000000}
\thead{Object}
        &   \mcp{\hfil \thead{Details}}
            &   \hfil\thead{Notes}                                   \\ 
        \hline
\endhead% head will appear on each new page with this table
\multirow[t]{6}{=}{Name}   
    &   Date \newline
        17/11/2016      &   Time (UTC):\newline
                            22:59:41-23:22:48
                            &   \multirow[t]{6}{=}{A total of 20
                                exposures all taken with an exposure
                                length of 60.0 seconds}     \\
    \cline{2-3}
    &   Filter/s used:\newline
        I, R, B, V      & quack!        &                   \\
    \cline{2-3}
    &   \mcp{Telescope/s used:\newline TELESCOPE}
                            &                               \\
    \hline
\multirow[t]{6}{=}{Name}
    &   Date \newline
        17/11/2016      &   Time (UTC):\newline
                            22:59:41-23:22:48
                            &   \multirow[t]{6}{=}{A total of 20
                                exposures all taken with an exposure
                                length of 60.0 seconds}     \\
    \cline{2-3}
    &   Filter/s used:\newline
        I, R, B, V      & quack, quack! &                   \\
    \cline{2-3}
    &   \mcp{Telescope/s used:\newline TELESCOPE}
                            &                               \\
    \hline
\end{tabularx}
}
\end{document}

单元格中的文本部分取自其他答案。

在此处输入图片描述

相关内容