枚举和换行 tabularx

枚举和换行 tabularx

我尝试在图表中进行枚举/换行,但无法做到。您能帮我找到合适的工具吗?

对于行优势,我尝试不进行基因组整合(无移码,甚至不会对基因组造成更严重的损害) => 换行 高灵活性

对于行培养细胞,我尝试列举以下 3 个词:电穿孔/脂质转染/微注射

谢谢

% page setup 
\documentclass[a4paper, 11pt]{article}
\usepackage[left=3cm,top=3cm,right=3cm]{geometry}
\usepackage{fancyvrb} 

% tables
\usepackage{booktabs} 
\usepackage{tabularx} 
\newcolumntype{C}{>{\Centering}X}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}

\begin{document}

\begin{table}[ht]
\scriptsize
\newlength\colwidth 
\settowidth\colwidth{30\% acrylamide stock solution30\%} % set width of 1st col.
\begin{tabularx}{\textwidth}{@{} P{\colwidth} *{2}{C} @{}}
    \toprule
& Transient transfection & Stable transfection\\
    \midrule
Advantages
    & no genomic integration (no frameshift, or even worse damage to the genome) high flexibility & \\
\addlinespace
cultured cells
    & electroporation / lipofection / microinjection\\
\bottomrule
\end{tabularx}
\endtabularx
\end{table}

\end{document}



答案1

表中有两个使用示例,还有一个使用不同表格设计的itemize示例:enumerate

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{fancyvrb}

% tables
\usepackage{ragged2e}   % <--- added
\usepackage{booktabs, tabularx}
\newcolumntype{C}{>{\Centering}X}
\newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X} % <--- new, for the last example
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}
\newlength\colwidth

\usepackage{enumitem}   % <--- new, for lists (in table)
\usepackage{etoolbox}   % <--- new, for customization of lists used in tables
\AtBeginEnvironment{table}{%
\setlist[itemize]{nosep,
                 leftmargin=*,
                 label=\textbullet, % <---
                 before=\begin{minipage}[t]{\linewidth}, 
                 after=\end{minipage}}                   

\setlist[enumerate]{nosep,
                 leftmargin=*,
                 label=\arabic*.,   % <---
                 before=\begin{minipage}[t]{\linewidth},  
                 after=\end{minipage}}                   
                        }

\begin{document}
With \verb+itemize+
    \begin{table}[ht]
\settowidth\colwidth{30\% acrylamide stock solution30\%} % set width of 1st col.
%
\begin{tabularx}{\textwidth}{@{} P{\colwidth} *{2}{C} @{}}
    \toprule
    & Transient transfection & Stable transfection  \\
    \midrule
Advantages
    &   \begin{itemize}
    \item   no genomic integration (no frameshift, or even worse damage to the genome) 
    \item   high flexibility 
        \end{itemize}   &   \\
\addlinespace
cultured cells
    &   \begin{itemize}
    \item   electroporation 
    \item   lipofection 
    \item    microinjection
        \end{itemize}   &   \\
\bottomrule
\end{tabularx}
    \end{table}
    
or with \verb+enumerate+:

    \begin{table}[ht]
\settowidth\colwidth{30\% acrylamide stock solution30\%} % set width of 1st col.
%
\begin{tabularx}{\textwidth}{@{} P{\colwidth} *{2}{C} @{}}
    \toprule
    & Transient transfection & Stable transfection  \\
    \midrule
Advantages
    &   \begin{enumerate}
    \item   no genomic integration (no frameshift, or even worse damage to the genome)
    \item   high flexibility
        \end{enumerate}   &   \\
\addlinespace
cultured cells
    &   \begin{enumerate}
    \item   electroporation
    \item   lipofection
    \item   microinjection
        \end{enumerate}   &   \\
\bottomrule
\end{tabularx}
    \end{table}
    
or with \verb+l+ and \verb+L+ types of table columns and \verb+enumerate+:

    \begin{table}[ht]
\begin{tabularx}{\textwidth}{@{} l *{2}{L} @{}}
    \toprule
    & Transient transfection & Stable transfection  \\
    \midrule
Advantages
    &   \begin{enumerate}
    \item   no genomic integration (no frameshift, or even worse damage to the genome)
    \item   high flexibility
        \end{enumerate}   &   \\
\addlinespace
cultured cells
    &   \begin{enumerate}
    \item   electroporation
    \item   lipofection
    \item   microinjection
        \end{enumerate}   &   \\
\bottomrule
\end{tabularx}
    \end{table}
\end{document}

在此处输入图片描述

附录: 如果您只想使用换行符。在这种情况下,您不需要enumitem andetoolbox` 包:

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{fancyvrb}

% tables
\usepackage{ragged2e}   % <--- added
\usepackage{booktabs, tabularx}
\newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X} % <--- new, for the last example

\begin{document}
...

您可以通过三种方式实现此目的:

  • 在您想要分隔单元格内容的地方插入空行:
Advantages
    &   no genomic integration (no frameshift, or even worse damage to the genome)

        high flexibility
        &   \\
  • 使用命令`verb+\linebreak+
Advantages
    &   no genomic integration (no frameshift, or even worse damage to the genome)\linebreak
        high flexibility
        &   \\
  • 或使用命令\par
Advantages
    &   no genomic integration (no frameshift, or even worse damage to the genome)\par
        high flexibility
        &   \\

在所有上述情况下,结果都是相同的:

在此处输入图片描述

答案2

您缺少ragged2e在你的序言中:

在此处输入图片描述

\documentclass{article}

% tables
\usepackage{booktabs,ragged2e}
\usepackage{tabularx} 
\newcolumntype{C}{>{\Centering}X}
\newcolumntype{P}[1]{>{\RaggedRight}m{#1}}

\begin{document}

\begin{table}[ht]
  \scriptsize
  \newlength\colwidth
  \settowidth\colwidth{30\% acrylamide stock solution30\%} % set width of 1st col.
  \begin{tabularx}{\textwidth}{@{} P{\colwidth} *{2}{C} @{}}
    \toprule
      & Transient transfection & Stable transfection \\
    \midrule
    Advantages
      & no genomic integration (no frameshift, or even worse damage to the genome) high flexibility & \\
    \addlinespace
    cultured cells
      & electroporation / lipofection / microinjection \\
    \bottomrule
  \end{tabularx}
\end{table}

\end{document}

相关内容