使用 \multirow 的垂直线

使用 \multirow 的垂直线

这是我的一点乳胶:

\begin{tabular}{ |p{1cm}|p{3cm}|p{8cm}| }
 \hline
\multicolumn{3}{|c|}{\textbf{Information Asset Risk Worksheet}} \\
 \hline 
\multicolumn{3}{|l|}{Information Asset: (hier typen)} \\
 \hline 
 \multicolumn{3}{|l|}{Area of Concern: (hier typen)} \\
 \hline 

  \multirow{6}{*}{\textbf{Threat}} & \textbf{(1)Actor} & ...\\ 
    & \textbf{(2)Means} & ...\\ 
   &  \textbf{(Motive)} & ...\\ 
    &  \textbf{(4)Outcome} & ...\\  
    &  \textbf{(5) Security Requirements} & ...\\ 
    &  \textbf{(6)Probability} & ...\\ \hline

\end{tabular}

结果如下:

在此处输入图片描述

尽管我使用了 \multirow,但我还是到处都得到了 hlines,或者根本得不到 hlines。如何在合并“threat”多行后得到 hlines?

韩国

答案1

像这样?

在此处输入图片描述

比你寻找的\cline{2-3}只在第二列和第三列画水平线(并且没有垂直线的问题,或者我误解了你的问题):

\documentclass{article}
\usepackage{array, multirow}

\begin{document}
{\renewcommand\arraystretch{1.3}
\begin{tabular}{ |p{1.5cm}|>{\bfseries\raggedright}p{2.75cm}|p{7.75cm}| }
    \hline
\multicolumn{3}{|c|}{\textbf{Information Asset Risk Worksheet}} \\
    \hline
\multicolumn{3}{|l|}{Information Asset: (hier typen)} \\
    \hline
\multicolumn{3}{|l|}{Area of Concern: (hier typen)} \\
    \hline
\multirow{6}{=}{\textbf{Threat}}
    &   (1) Actor                   & ...   \\
    \cline{2-3}
    &   (2) Means                   & ...   \\
    \cline{2-3}
    &   (3) Motive)                 & ...   \\
    \cline{2-3}
    &   (4) Outcome                 & ...   \\
    \cline{2-3}
    &   (5) Security Requirements   & ...   \\
    \cline{2-3}
    &   (6) Probability             & ...   \\
    \hline
\end{tabular}
}
\end{document}

我也稍微简化了表格代码。

答案2

TeXnician 的答案有一点缺陷,“威胁”这个词没有完全垂直对齐,如果你创建一个包含多行文本的单元格,你就可以很容易地看到它(参见下面的第一个表格)。

为了避免这种情况,我建议您创建一个主表,其中一行由一个单元格组成,单元格中有一个单词“Threat”,另一个单元格包含主表的其余部分,其中包含一个“子表”。这样就不会出现对齐问题(见下面的第二个表格)。

\documentclass[a4paper]{article}
\usepackage[lmargin=3cm]{geometry}%only to avoid overfull hbox in my mwe, since your mwe is not complete we don't know the exact geometry of your document

\usepackage{array, multirow}
\renewcommand\arraystretch{1.3}
\newcolumntype{B}[1]{>{\bfseries\raggedright}p{#1}}
\newcolumntype{L}[1]{>{\bfseries\raggedright}m{#1}}

\begin{document}
\TeX{}nician's answer:
\begin{center}
\begin{tabular}{ |p{1.5cm}|>{\bfseries\raggedright}p{2.75cm}|p{7.75cm}| }
    \hline
\multicolumn{3}{|c|}{\textbf{Information Asset Risk Worksheet}} \\
    \hline
\multicolumn{3}{|l|}{Information Asset: (hier typen)} \\
    \hline
\multicolumn{3}{|l|}{Area of Concern: (hier typen)} \\
    \hline
\multirow{6}{=}{\textbf{Threat}}
    &   (1) Actor                   
        & In \TeX{}nician's answer the word \textbf{Threat} is not perfectly 
          vertically aligned, you can easily see it if you create a cell with
          more than one line of text\\
    \cline{2-3}
    &   (2) Means                   & ...   \\
    \cline{2-3}
    &   (3) Motive                & ...   \\
    \cline{2-3}
    &   (4) Outcome                 & ...   \\
    \cline{2-3}
    &   (5) Security Requirements   & ...   \\
    \cline{2-3}
    &   (6) Probability             & ...   \\
    \hline
\end{tabular}
\end{center}

My suggestion:
\begin{center}
\begin{tabular}{ |m{1.5cm}|m{2.75cm}|m{7.75cm}| }
    \hline
    \multicolumn{3}{|c|}{\textbf{Information Asset Risk Worksheet}} \\
    \hline
    \multicolumn{3}{|l|}{Information Asset: (hier typen)} \\
    \hline
    \multicolumn{3}{|l|}{Area of Concern: (hier typen)} \\
    \hline
    \textbf{Threat}
        & \multicolumn{2}{@{}c@{}}{% a "sub"-table
            \begin{tabular}{B{2.75cm}|p{7.75cm}|}
                (1) Actor                   
                    & With my solution the word \textbf{Threat} is always 
                      perfectly aligned, whatever is the content of the other 
                      cells\\
                \hline
                (2) Means & ...   \\
                \hline
                (3) Motive                & ...   \\
                \hline
                (4) Outcome                 & ...   \\
                \hline
                (5) Security Requirements   & ...   \\
                \hline
                (6) Probability             & ...   \\
            \end{tabular}% end of the sub-table
          }% end of the \multicolumn
        \\% end of row with "Threat" and the sub-table
    \hline
\end{tabular}
\end{center}
\end{document}

在此处输入图片描述

相关内容