我怎样才能给我的身材更多的空间?

我怎样才能给我的身材更多的空间?

我正在制作一个表格,表格的列下面有一些文字。我想把它做成一个图形,但当我这样做时,列下面的文字与图形标签发生冲突。见附图

在此处输入图片描述

代码如下:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{pifont}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\begin{document}

        \begin{figure}[t]
            \centering
            % need the pifont package
            \begin{tabular}{l|l|l|l|l}
                %\begin{tabular}{l|l|l|l|l}                                                                  
                \multicolumn{2}{c}{}&\multicolumn{2}{c}{True Label}&\\
                \cline{3-4}
                \multicolumn{2}{c|}{}&\multicolumn{1}{c|}{Positive}&\multicolumn{1}{c|}{Negative}&\multicolumn{1}{c}{}\\
                %\cline{2-4}                                                                                 
                \hhline{~|---}
                \multirow{2}{*}{Predicted Label}& Positive & TP & FP ($\alpha$) &\ding{214} PPV\\
                %\cline{2-4}                                                                                 
                \hhline{~|---}
                & Negative & FN ($\beta$) & TN & \ding{214} NPV\\
                %\cline{2-4}                                                                                 
                \hhline{~|---}
                \multicolumn{1}{c}{} & \multicolumn{1}{c}{} &
                \multicolumn{1}{c}{\multirow{2}{*}{\parbox{2em}{\vskip1ex\ding{215}\\ Se}}} & \multicolumn{1}{c}{\multirow{2}{*}{\parbox{2em}{\vskip1ex\ding{215}\\ Sp}}} &\multicolumn{1}{c}{}\\
            \end{tabular}
            \caption{Confusion Matrix}{A typical confusion matrix for a binary classifcation problem.}
            \label{confusionmatrix}

        \end{figure}


\end{document}

答案1

虽然这不是你问题的答案,但你的例子表明我使用的某些宏可能会对你有所帮助。它们生成双向列联表,例如

在此处输入图片描述

代码并不像它可能的那样漂亮或通用,但它就是我所需要的。(我确信我在这个网站的答案中找到了大多数想法,当时肯定会得到赞成 - 但我现在找不到放在这里的链接。)

在序言中:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Table packages
%
\usepackage{multirow}
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{booktabs}% http://ctan.org/pkg/booktabs

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% formatting contingency tables
% 
\newcommand{\thecondition}{to be renewed}
\newcommand{\theyes}{to be renewed}
\newcommand{\theno}{to be renewed}
\newlength{\tempdima}

\newcommand{\ctablehead}[3]{%
   \settowidth{\tempdima}{#1}% compute width needed
   \addtolength{\tempdima}{-\arraycolsep}% minus default column sep
   \renewcommand{\thecondition}{#1}
   \renewcommand{\theyes}{#2}
   \renewcommand{\theno}{#3}
}
\newcommand{\ctablebody}{%
\cline{3-5}
& &   \multicolumn{2}{c|}{\thecondition} & \\ 
& &   {\makebox[0.5\tempdima]{\theyes}} 
    & {\makebox[0.5\tempdima]{\theno}} 
    & {total} \\
\hline
}

在文档中:

\ctablehead{chronic fatigue syndrome}{yes}{no}
{\renewcommand{\arraystretch}{1.2}% for the vertical padding
\begin{tabular}{cc
|
S[table-format=3.0]
S[table-format=5.0]
|
S[table-format=6.0]
|
}
\ctablebody
\multicolumn{1}{|c}{\multirow{2}{*}{tested positive}} &
\multicolumn{1}{c|}{yes} &  203  &   6802  & 7005 \\
\multicolumn{1}{|c}{}        &                
\multicolumn{1}{c|}{no} &  32  &  92963 & 92885 \\
\hline
\multicolumn{1}{|c}{}
 & total & 235 & 99765 & 100000 \\
\hline
\end{tabular}
}

答案2

主要错误是您的多行跨越了表格的末尾。

在此处输入图片描述

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{pifont}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\begin{document}

        \begin{figure}[t]
            \centering
            % need the pifont package
            \begin{tabular}{l|l|l|l|l}
                %\begin{tabular}{l|l|l|l|l}                                                                  
                \multicolumn{2}{c}{}&\multicolumn{2}{c}{True Label}&\\
                \cline{3-4}
                \multicolumn{2}{c|}{}&\multicolumn{1}{c|}{Positive}&\multicolumn{1}{c|}{Negative}&\multicolumn{1}{c}{}\\
                %\cline{2-4}                                                                                 
                \hhline{~|---}
                \multirow{2}{*}{Predicted Label}& Positive & TP & FP ($\alpha$) &\ding{214} PPV\\
                %\cline{2-4}                                                                                 
                \hhline{~|---}
                & Negative & FN ($\beta$) & TN & \ding{214} NPV\\
                %\cline{2-4}
                \hhline{~|---}                                                                     
                \multicolumn{2}{c}{\rule{0pt}{15pt}}&\multicolumn{1}{c}{\ding{215}}& \multicolumn{1}{c}{\ding{215}} &\\
                \multicolumn{2}{c}{}&\multicolumn{1}{c}{se}& \multicolumn{1}{c}{sp} &\\
            \end{tabular}
            \caption{Confusion Matrix}{A typical confusion matrix for a binary classifcation problem.}
            \label{confusionmatrix}

        \end{figure}


\end{document}

答案3

问题出在你的\multirow语句上。它们的目的是合并多行,而不是将现有的单行拆分成多行。如果你改用\parbox,那就没问题了。

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{pifont}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\begin{document}

        \begin{figure}[t]
           \centering
           % need the pifont package
           \begin{tabular}{l|l|l|l|l}
           %\begin{tabular}{l|l|l|l|l}                                                                  
           \multicolumn{2}{c}{}&\multicolumn{2}{c}{True Label}&\\
           \cline{3-4}
           \multicolumn{2}{c|}{}&\multicolumn{1}{c|}{Positive}&\multicolumn{1}{c|}{Negative}&\multicolumn{1}{c}{}\\
           %\cline{2-4}                                                                                 
           \hhline{~|---}
           \multirow{2}{*}{Predicted Label}& Positive & TP & FP ($\alpha$) &\ding{214} PPV\\
           %\cline{2-4}                                                                                 
           \hhline{~|---}
           & Negative & FN ($\beta$) & TN & \ding{214} NPV\\
           %\cline{2-4}                                                                                 
           \hhline{~|---}
           \multicolumn{2}{c}{}  &
           \multicolumn{1}{c}{\parbox{1em}{\ding{215}\\ Se}} & \multicolumn{1}{c}{\parbox{1em}{\ding{215}\\ Sp}}\\
           \end{tabular}
           \caption{Confusion Matrix}{A typical confusion matrix for a binary classifcation problem.}
           \label{confusionmatrix}

        \end{figure}


\end{document}

相关内容