需要将文本换行到一列中

需要将文本换行到一列中

列内的某些文本应该换到下一行,但是从下面的代码中我看到,文本长度太大,会干扰最右边的列。

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{array}
\usepackage{ragged2e}
\usepackage{multirow}

\begin{document}
The table \ref{label1} 

  \begin{table} 
  \centering    
  \caption{my table}
  \label{label1}
  \begin{tabular}{ |l|p{4cm}|p{1cm}| }
    \hline
    A & B & C \\ 
    \hline
     \multirow{3}{*}{Gromacs}   &  \texttt{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}    &    62\%   \\
                               &  \texttt{bbbbbb}     &    15 \%   \\ 
                               &  \texttt{cccccccccccccccccccccccccccccc}   &   10\%   \\
    \hline
  \end{tabular}
  \end{table}

\end{document}

输出如下所示

在此处输入图片描述

答案1

这是一个解决方案,使用tabularxxurl。我添加了一个变体,它可以自动在整个列中进行自动换行,以防第二列中的所有单元格(列标题除外)都应以这种方式输入,使用包collcell

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{tabularx}
\usepackage{seqsplit}
\usepackage{xurl, collcell}
\newcolumntype{U}{>{\collectcell\url}X <{\endcollectcell}}

\usepackage{multirow}
\AtBeginDocument{\def\UrlFont{\tt}}

\begin{document}

\noindent Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

The table \ref{label1}
  \begin{table}[!h]
\centering%
\setlength{\extrarowheight}{2pt}
  \caption{my table}
  \label{label1}
  \begin{tabularx}{\columnwidth}{ |l|U|l| }
    \hline
    A & \multicolumn{1}{l}{B }& C \\
    \hline
     \multirow{3}{*}{Gromacs} & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & 62\% \\
                               & non_bonded_Elec_uiF_pos_non_bonded_Elec_uiF_pos & 15 \% \\
                               & cccccccccccccccccccccccccccccc & 10\% \\
    \hline
  \end{tabularx}
  \end{table}

\noindent Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.
  \begin{table}[!h]
\centering%
\setlength{\extrarowheight}{2pt}
  \caption{my table}
  \label{label1a}
  \begin{tabularx}{\columnwidth}{ |l|X|l| }
    \hline
    A & B & C \\
    \hline
     \multirow{3}{*}{Gromacs} & \url{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}& 62\% \\
                               & \url{non_bonded_Elec_uiF_pos_non_bonded_Elec_uiF_pos} & 15 \% \\
                               & \url{cccccccccccccccccccccccccccccc} & 10\% \\
    \hline
  \end{tabularx}
  \end{table}
noindent Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

\end{document} 

在此处输入图片描述

相关内容