使用表格格式

使用表格格式

我一直在尝试创建表格作为我论文的一部分,由于我是 Latex 的新手,因此在表格格式方面遇到了问题。首先,我希望在文本和水平线上方留出一些空间,并且只希望标题(顶部单元格)居中对齐(垂直)。我使用的代码是:

\documentclass[a4paper, 12pt, twoside, openright]{report}
\usepackage{mathtools, array, multirow, booktabs}
\begin{document}
Some contents...

\begin{table}
\centering
\footnotesize
\caption{Guidelines for excavation and support of rock tunnels in accordance to RMR.}
  \begin{tabular}{@{} p{0.15\textwidth} p{0.15\textwidth} p{0.2\textwidth} p{0.2\textwidth} p{0.2\textwidth} @{}}
    \toprule
    \multirow{2}{0.13\textwidth}{\textbf{Rock Mass Class\newline
    (RMR value range)}}&    \multirow{2}{0.15\textwidth}{\textbf{Excavation}}&  \multicolumn{3}{c}{\textbf{Supports}}\\
    \cline{3-5}
    &   &   \textbf{Rock bolts (20 mm diameter, fully grouted)}&    \textbf{Conventional shotcrete}&    \textbf{Steel Sets}\\
    \addlinespace
    \hline
    Very Good Rock\newline
    \textit{81-100}&    Full face; 3 m advance& \multicolumn{3}{c}{Generally, no support required except for occasional spot bolting}\\
    \addlinespace
    Good Rock \newline
    \textit{61-80}& Full face; 1.0-1.5 m advance; complete support 20 m from face&  Locally, bolts in crown 3m long, spaced 2.5 m with occasional wire mesh&    50 mm in crown where required&  None\\
    \addlinespace   
    Fair Rock\newline
    \textit{41-60}& Heading and bench; 1.5-3 m advance in heading; commence support after each blast; complete support 10 m from face&  Systematic bolts 4 m long, spaced1.5-2.0 m in crown and walls with wire mesh in crown&  50-100 mm in crown and 30 mm in sides&  None\\
    \end{tabular}
\end{table}

Some contents
\end{document}

PS 就像我说过的,我是 Latex 的新手,并且在原文中使用了很多包,我可能错过了这个 MWE 中的某些包。

我想要获得的表格应该是这样的

在此处输入图片描述

答案1

我可能会把它放在横向页面上。下面是使用 的尝试tabularx,仅供您参考:

\documentclass[a4paper, 12pt, twoside, openright]{report}
\usepackage{mathtools, array, multirow, booktabs}
\usepackage{tabularx}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{lipsum}
\newcolumntype{Y}{>{\hsize=\dimexpr3\hsize+3\tabcolsep+2\arrayrulewidth\relax}X}
\begin{document}
\lipsum

\afterpage{%
    \clearpage%
    \begin{landscape}
        \begin{table}[p]
        \centering
        \caption{Guidelines for excavation and support of rock tunnels in accordance to RMR.}
          \begin{tabularx}{\linewidth}{XXXXX}
            \toprule
            \multirow{2}{\hsize}{\textbf{Rock Mass Class (RMR value range)}}&    \multirow{2}{\hsize}{\textbf{Excavation}}&\multicolumn{3}{Y}{\textbf{Supports}}\\
            \cmidrule(lr){3-5}
            &   &   \textbf{Rock bolts (20 mm diameter, fully grouted)}&    \textbf{Conventional shotcrete}&    \textbf{Steel Sets}\\
            \midrule
            Very Good Rock\newline
            \textit{81-100}&    Full face; 3 m advance& \multicolumn{3}{Y}{Generally, no support required except for occasional spot bolting}\\
            \addlinespace
            Good Rock \newline
            \textit{61-80}& Full face; 1.0--1.5 m advance; complete support 20 m from face&  Locally, bolts in crown 3m long, spaced 2.5 m with occasional wire mesh&    50 mm in crown where required&  None\\
            \addlinespace   
            Fair Rock\newline
            \textit{41-60}& Heading and bench; 1.5--3 m advance in heading; commence support after each blast; complete support 10 m from face&  Systematic bolts 4 m long, spaced 1.5--2.0 m in crown and walls with wire mesh in crown&  50--100 mm in crown and 30 mm in sides&  None\\
            \bottomrule
            \end{tabularx}
        \end{table}
    \end{landscape}
}
\lipsum
\end{document}

在此处输入图片描述

这定义了一种新的列类型,Y基本上是三X列 --- 这是在 s 中使用\multicolumn。我忽略了定义一种新的两列列类型X,因为只需要一次,但如果您发现自己再次需要它,那么定义另一个列类型是有意义的(Z比如说)。

整个事情显然远非完美,但我认为它会给你一个开始 --- 并且我可能会在你获得所有信息之后再摆弄具体的格式。

答案2

此表格非常接近您的目标。它非常适合横向显示,字体大小也易于阅读。

它是使用包制作的nicematrix。它提供了创建多列和多行单元格的命令\Block,因此代码更紧凑、更易于阅读和维护。

\Block[l]{6-1}{<..>}创建一个 6 行 1 列的单元格。(只需学习一个新命令!)

最重要的是,它允许您使用\\内部,从而在阅读时在最有意义的地方剪切线条。见最后一张图。

允许\newcolumntype{P}{>{\raggedright\arraybackslash}p{0.15\textwidth}}调整五列的宽度以适合文本区域,并且还可以避免raggedright单词之间出现尴尬的空格。

d

\documentclass[a4paper, 12pt]{report}

\usepackage{pdflscape} % landscape  added <<<<<<<<<
\usepackage{geometry}% added <<<<<<<<<

\usepackage{caption}
\usepackage{booktabs} % rules
\usepackage{nicematrix} % added <<<<<<<<<
\newcolumntype{P}{>{\raggedright\arraybackslash}p{0.15\textwidth}}

\begin{document}
    
    \begin{landscape}
        \setlength{\oddsidemargin}{-15pt} % shift up the table
        \pagestyle{empty}   
        \begin{table}[ht!]
            \centering
            \footnotesize
            \caption{Guidelines for excavation and support of rock tunnels in accordance to RMR.}   
            \begin{NiceTabular}{@{}P P P P P @{}}
                \toprule
                &&  \Block{1-3}{\bfseries Supports} &&\\  % headings of the table
                \cline{3-5}
                \Block{2-1}<\bfseries>{Rock Mass \\Class}  &    
                \Block{2-1}<\bfseries>{Excavation}&  
                \Block{3-1}<\bfseries>{Rock bolts \\ (20mm diameter, \\fully grouted)} & 
                \Block{3-1}<\bfseries>{Conventional \\ shotcrete} & 
                \Block[l]{3-1}<\bfseries>{Steel Sets}  \\ 
                &&&&\\       &&&& \\    % two  empty rows
                \midrule
                &&&& \\
                \Block[l]{2-1}{Very Good Rock \\ \textit{RMR = 81--100}}&    %Row #1
                \Block[l]{2-1}{Full face; \\ 3m advance}&  
                \Block{2-3}{Generally, no support required except for\\ occasional spot bolting} && \\          
                &&&&\\       &&&&\\     % two more empty rows   
                
                \Block[l]{2-1}{Good Rock \\ \textit{RMR = 61--80}}&  %Row #2
                \Block[l]{4-1}{Full face; 1.0-1.5m \\ advance; complete \\support 20m from \\face}&
                \Block[l]{5-1}{Locally, bolts in  \\crown 3m long, \\spaced 2.5m with\\ occasional wire\\ mesh}&  
                \Block[l]{2-1}{50mm in crown \\ where required}&  
                \Block[l]{1-1}{None}\\              
                &&&&\\   &&&&\\  &&&&\\  &&&&\\ &&&&\\  % five more empty rows  
                
                \Block[l]{2-1}{Fair Rock \\ \textit{RMR = 41--60}}&  %Row #3
                \Block[l]{7-1}{Heading and bench; \\ 1.5--3m advance in\\ heading; commence\\ support after each\\ blast; complete\\ support 10m from\\ face}& 
                \Block[l]{5-1}{Systematic bolts\\ 4m long, spaced\\ 1.5--2.0m  in crown \\and walls with wire\\ mesh in crown}&  \Block[l]{3-1}{50-100mm in \\crown and 30mm \\in sides}&
                \Block[l]{1-1}{None}\\
                &&&&\\      &&&&\\      &&&&\\      &&&&\\          &&&&\\      &&&&\\      &&&&\\  % seven more empty rows 
                
                \Block[l]{2-1}{Poor Rock \\ \textit{RMR = 21--40}}&  %Row #4
                \Block[l]{7-1}{Top heading and bench; \\ 1.0--1.5m advance in\\top  heading; commence\\ install support \\ concurrently\\ with excavation\\  10m from face}& 
                \Block[l]{5-1}{Systematic bolts\\ 4--5m long, spaced\\ 1--1.5m  in crown \\and walls with wire\\ mesh}&  \Block[l]{3-1}{50-150mm in \\crown and 100mm \\in sides}&
                \Block[l]{3-1}{ Light to medium \\ ribs spaced 1.5m \\where required}\\     
                &&&&\\      &&&&\\      &&&&\\      &&&&\\      &&&&\\      &&&&\\      &&&&\\% seven more empty rows
                
                \Block[l]{2-1}{Very Poor Rock \\ \textit{RMR < 20}}&  %Row #5 last
                \Block[l]{8-1}{Multiple drift;\\ 0.5--1.5m advance in \\top heading; install\\ support concurrently\\ with excavation; \\shotconcrete as soon\\ as possible after \\ blasting}&
                \Block[l]{5-1}{Systematic bolts\\ 5--6m long, spaced\\ 1--1.5m  in crown \\and walls with wire\\ mesh; bolts inverts}&  \Block[l]{4-1}{150-200mm in \\crown, 150mm \\in sides and 50mm  \\on face}&
                \Block[l]{6-1}{Medium  to heavy\\ ribs spaced 0.75m \\with steel lagging \\and forepoling if \\required; close\\ invert}\\
                &&&&\\      &&&&\\      &&&&\\      &&&&\\      &&&&\\      &&&&\\      &&&&\\  % seven more empty rows     
                \bottomrule     
            \end{NiceTabular}
            
        \end{table}
    \end{landscape} 
    
\end{document}

第一次将会编译两次。

行越长,越容易阅读和理解。

ff

答案3

使用sidewaystabletabularxmulticellsiunitx

\documentclass[a4paper, 12pt, twoside, openright]{report}
\usepackage{ragged2e}
\usepackage{rotating}
\usepackage{booktabs, makecell, multirow, tabularx}
\renewcommand\theadfont{\footnotesize\bfseries}
\renewcommand\theadgape{}
\newcolumntype{L}[1]{>{\RaggedRight\hspace{0pt}%
                       \hsize=#1\hsize}X}
\usepackage{siunitx}

\begin{document}
\begin{sidewaystable}[ht]
\centering
\footnotesize
\caption{Guidelines for excavation and support of rock tunnels in accordance to RMR.}
\sisetup{range-units = single}
  \begin{tabularx}{\linewidth}{@{} L{0.7}
                              *{2}{L{1.4}} 
                                   L{1}
                                   L{0.5} @{}}
    \toprule
\multirow{4}{=}{\textbf{Rock Mass Class (RMR value range)}}
    &   \multirow{4}{=}{\textbf{Excavation}}
        &   \multicolumn{3}{c}{\textbf{Supports}}\\
    \cmidrule{3-5}
    &   &   \thead{Rock bolts\\ 
                  (diameter: \SI{20}{\milli\metre},\\ 
                   fully grouted)}
            &   \thead{Conventional\\ shotcrete}
                &    \thead{Steel\\Sets}\\
    \midrule
Very Good Rock \textit{81-100}
    &    Full face; \SI{3}{m} advance
        & \multicolumn{3}{c}{Generally, no support required except for occasional spot bolting}\\
    \addlinespace
Good Rock\newline 
\textit{61-80}
    & Full face; \SIrange{1.0}{1.5}{\metre} advance; complete support \SI{20}{\metre} from face
        &  Locally, bolts in crown \SI{3}{\metre} long, 
           spaced \SI{2.5}{\metre} with occasional wire mesh
           & \SI{50}{\milli\metre} in crown where required
            &  None\\
    \addlinespace
Fair Rock\newline 
\textit{41-60}
    & Heading and bench; \SIrange{1.5}{3}{\metre} advance in heading; commence support after each blast; complete support \SI{10}{\metre} from face
        &  Systematic bolts \SI{4}{\metre} long, spaced \SIrange{1.5}{2.0}{\metre} in crown and walls with wire mesh in crown
            & \SIrange{50}{100}{\milli\metre} in crown and \SI{30}{\milli\metre} in sides
                &  None\\
    \bottomrule
    \end{tabularx}
\end{sidewaystable}
\end{document}

在此处输入图片描述

答案4

另一种替代布局:

在此处输入图片描述

\documentclass[a4paper, 12pt, twoside, openright]{report}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, tabularx}
\renewcommand\theadfont{\footnotesize\bfseries}
\newcolumntype{L}[1]{>{\RaggedRight\hspace{0pt}%
                       \hsize=#1\hsize}X}
\usepackage{siunitx}
\usepackage{caption}

\begin{document}
\begin{table}
\centering
\small
\setlength{\tabcolsep}{4pt}
\caption{Guidelines for excavation and support of rock tunnels in accordance to RMR.}
\sisetup{range-units = single}
  \begin{tabularx}{\linewidth}{@{\qquad}L{1.3}L{0.95} L{0.8} L{0.95}@{}}
    \toprule
      \textbf{Excavation}
        &   \multicolumn{3}{c}{\textbf{Supports}}\\
    \cmidrule{2-4}
       &   \thead[l]{Rock bolts\textsuperscript{a}}
            &   \thead{Conventional\\ shotcrete}
                &    \thead[l]{Steel Sets}\\
    \midrule
\multicolumn{4}{@{}l}{Very Good Rock, RMR = 81--100}\\
        Full face; \SI{3}{m} advance
        & \multicolumn{3}{L{2.7}}{Generally, no support required except for occasional spot bolting}
        \\ \addlinespace
        
\multicolumn{4}{@{}l}{Good Rock, RMR = 61--80}\\
     Full face; \SIrange{1.0}{1.5}{\m} advance; complete support \SI{20}{\m} from face
        &  Locally, bolts in crown \SI{3}{\m} long, 
           spaced \SI{2.5}{\m} with occasional wire mesh
           & \SI{50}{\mm} in crown where required
            &  None\\ \addlinespace
            
\multicolumn{4}{@{}l}{Fair Rock, RMR = 41--60}\\
     Heading and bench; \SIrange{1.5}{3}{\m} advance in heading; commence support after each blast; complete support \SI{10}{\m} from face
        &  Systematic bolts \SI{4}{\m} long, spaced \SIrange{1.5}{2.0}{\m} in crown and walls with wire mesh in crown
            & \SIrange{50}{100}{\mm} in crown and \SI{30}{\mm} in sides
                &  None\\  \addlinespace
                
\multicolumn{4}{@{}l}{Poor Rock RMR = 21--40}\\
    Top heading and bench;  \SIrange{1.0}{1.5}{\m} advance in top  heading; commence install support  concurrently with excavation  \SI{10}{\m} from face
         & Systematic bolts \SIrange{4}{5}{\m} long, spaced \SIrange{1}{1.5}{\m}  in crown and walls with wire mesh
           &  \SIrange{50}{150}{\mm} in crown and \SI{100}{\m} in sides
             & Light to medium  ribs spaced \SI{1.5}{\m} where required\\  \addlinespace
                                 
\multicolumn{4}{@{}l}{Very Poor Rock RMR < 20}\\
    Multiple drift; \SIrange{0.5}{1.5}{\m} advance in top heading; install support concurrently with excavation; shotconcrete as soon as possible after  blasting
       & Systematic bolts \SIrange{5}{6}{\m} long, spaced \SIrange{1}{1.5}{\m} in crown and walls with wire mesh; bolts inverts
           &  \SIrange{150}{200}{\mm} in crown, \SI{150}{\mm} in sides and \SI{50}{\mm} on face
               & Medium  to heavy ribs spaced \SI{0.75}{\m} with steel lagging and forepoling if required; close invert\\   
                               
    \bottomrule
    \multicolumn{4}{p{\dimexpr\linewidth-2\tabcolsep}}{\textsuperscript{a} diameter: \SI{20}{\mm}, fully grouted}\\
    \end{tabularx}
\end{table}
\end{document}

相关内容