如果您编译下面给出的代码,则显示“平均预身份验证响应时间”的行是合理的,因为单词之间有很大的间距。我希望它左对齐。此外,如果需要换行,那么我可以让 LaTeX 优先保留整个单词,并在有空间的情况下将其移至下一行吗?在这种情况下,有一个连字符并且单词正在断开,但有足够的空间让整个单词向下移动。
\documentclass{article}\usepackage[]{graphicx}\usepackage[]{color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
\usepackage{alltt}
\usepackage{graphicx,booktabs}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
%% for inline R code: if the inline code is not correctly parsed, you will see a message
\newcommand{\rinline}[1]{SOMETHING WRONG WITH knitr}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\colorlet{tableheadcolor}{blue!25}
\colorlet{fail}{red}
\colorlet{passPoor}{yellow}
\colorlet{passGood}{green!50}
\colorlet{optimal}{green}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\addtolength{\oddsidemargin}{-.875in}
\addtolength{\evensidemargin}{-.875in}
\addtolength{\textwidth}{1.75in}
\addtolength{\topmargin}{-.875in}
\addtolength{\textheight}{1.75in}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
\section{Summary}
\begin{flushleft}
\begin{table}[htbp]
\small
\centering
\caption{Brief overview of the Results}
\begin{tabularx}{0.75\textwidth}{XX}
%\hline
\toprule
\rowcolor{tableheadcolor}
Metrics for machine & \textbf{Result} \\
%\hline
\midrule
Failure Rate & 0.00\% \\
Lorema LoremLore Lore & 0.0 sec \\
Average Pre-Authentication (ASD) Response Time & 0.0 sec \\
Overall Result & \cellcolor{passGood}Passed \\
%\hline
\bottomrule
\end{tabularx}%
\label{tab:overviewOld}%
\normalsize
\end{table}
\end{flushleft}
\end{document}
答案1
收集帖子评论中包含的一些信息:
类型列中的文本排版
X
是“完全对齐”的。根据允许的连字符断点的可用性(不可用性),这可能会导致列变得难看,因为可用空间中挤满了太少或太多的文本。将表格第一列的文本材料以“右对齐”的方式排版没有允许连字符,将列说明符替换
X
为>{\raggedright}X
将
>
符号视为将其参数“推入”\raggedright
到的列规范中X
。使用该规范的一个缺点
\raggedright
是,生成的材料看起来非常粗糙。要启用右对齐排版,同时允许 LaTeX 在单词内的连字符处插入换行符,请务必加载包ragged2e
(代码中已完成)并使用列规范>{\RaggedRight}X
请注意两个大写的 R 字母。