首页 > 解决方案 > 当在 latex 中使用 \textbf 时,它会改变里面的值的位置

问题描述

我正在尝试使用乳胶显示我的结果表,但我在显示时遇到了一些问题:应用粗体时数字不居中,你能帮我找出原因,在代码下方以及它的样子:


\documentclass[a4paper, 11pt, french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}% Include the listings-package
\usepackage{listings} 
\lstset{language=python} 
\usepackage[table]{xcolor}
\usepackage{collcell}
\usepackage{hhline}
\usepackage{pgf}
\usepackage{comment} % habilita el uso de comentarios en varias lineas (\ifx \fi) 
\usepackage{lipsum} %Este paquete genera texto del tipo  Lorem Ipsum. 
\usepackage{fullpage} % cambia el margen
\usepackage{booktabs} % Required for better horizontal rules in tables
\usepackage{fouriernc} % Use the New Century Schoolbook font
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{siunitx}
\usepackage{graphicx}


\begin{document}

\begin{table}[ht]
  \begin{tabular}{lSSS}
    \toprule
    \multirow{2}{*}{Models} &
      \multicolumn{1}{c}{POS} \\
      & {N+POS - P}  \\ % & {V+N+L-P, S} & {V+N+L-P, S, Ne}
      \midrule
    LinearSVC & 0.44 \\ %& \textbf{0.58} & \textbf{0.58}  \\
    MultinomialNb & 0.51 \\ %& 0.51 & 0.51  \\
    LogisticRegression & 0.53 \\ %& 0.51 & 0.51  \\
    RandomForestClassifier & \textbf{0.55} \\ %& 0.56 & 0.57  \\
    KNeighborsClassifier & 0.48 \\ %& 0.50 & 0.49  \\
    \bottomrule
  \end{tabular}
\end{table}


\end{document}

结果是这样的:

在此处输入图像描述

如您所见,0.55 与其他值并不完全一致

标签: machine-learninglatexlatex-environment

解决方案


我相信这与您给列的对齐方式有关。

在您的\begin{tabular}{lSSS}行中,您声明了 4 列,即使您评论了其中的 2 列。它对我来说仍然是这样,但要考虑到l左对齐,并且由于粗体效果会增加字母的宽度,如果你左对齐,它仍然会看起来更大。如果您希望值居中,我建议您使用c而不是 S。

我就是这样做的,希望对你有用:

  1. 使用左对齐的解决方案:
\begin{table}[ht]
  \begin{tabular}{ll}
    \toprule
    \multirow{2}{*}{Models} &
      \multicolumn{1}{c}{POS} \\
      & {N+POS - P}  \\ % & {V+N+L-P, S} & {V+N+L-P, S, Ne}
      \midrule
    LinearSVC & 0.44 \\ %& \textbf{0.58} & \textbf{0.58}  \\
    MultinomialNb & 0.51 \\ %& 0.51 & 0.51  \\
    LogisticRegression & 0.53 \\ %& 0.51 & 0.51  \\
    RandomForestClassifier & \textbf{0.55} \\ %& 0.56 & 0.57  \\
    KNeighborsClassifier & 0.48 \\ %& 0.50 & 0.49  \\
    \bottomrule
  \end{tabular}
\end{table}

在我看来是这样的: 在此处输入图像描述

  1. 使用中心对齐的解决方案
\begin{table}[ht]
  \begin{tabular}{lc}
    \toprule
    \multirow{2}{*}{Models} &
      \multicolumn{1}{c}{POS} \\
      & {N+POS - P}  \\ % & {V+N+L-P, S} & {V+N+L-P, S, Ne}
      \midrule
    LinearSVC & 0.44 \\ %& \textbf{0.58} & \textbf{0.58}  \\
    MultinomialNb & 0.51 \\ %& 0.51 & 0.51  \\
    LogisticRegression & 0.53 \\ %& 0.51 & 0.51  \\
    RandomForestClassifier & \textbf{0.55} \\ %& 0.56 & 0.57  \\
    KNeighborsClassifier & 0.48 \\ %& 0.50 & 0.49  \\
    \bottomrule
  \end{tabular}
\end{table}

它看起来像这样: 在此处输入图像描述

现在你需要决定哪一个更适合你。


推荐阅读