文本不适合该列

文本不适合该列

这是我的文件:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape, margin=0.5in]{geometry}

\title{ABC}

\begin{document}

\maketitle

\section{First}
\begin{center}
        \begin{tabular}{|*{8}{c|}}
            \textbf{A} &  
            \textbf{B} &  
            \textbf{C} &  
            \textbf{D} &
            \textbf{E} &               
            \textbf{F} & 
            \textbf{G} & 
            \textbf{H}\\
        \hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It' too long, it's too long, it's too looooooooooooooooooooooog\\
        \end{tabular}
\end{center}
\end{document}

\hbox 过满(2099.37712pt 太宽)
一列框中可以有多行吗(双斜线不起作用)?
例如:

it' too long, it's too long,  
it's too looooooooooooooooooooooog

答案1

对于列中的自动换行,请使用p具有适当宽度参数的固定宽度列类型,而不是c其本身也与其最宽条目一样宽。在下面的 MWE 中,我还添加了>{\raggedright\arraybackslash}(需要array包)以确保此特定单元格中的内容右对齐,而不是两端对齐,这是p类型列中的默认对齐方式。

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape, margin=0.5in]{geometry}
\usepackage{array}
\title{ABC}

\begin{document}

\maketitle

\section{First}
\begin{center}
        \begin{tabular}{|*{7}{c|}>{\raggedright\arraybackslash}p{5.5cm}|}
            \textbf{A} &  
            \textbf{B} &  
            \textbf{C} &  
            \textbf{D} &
            \textbf{E} &               
            \textbf{F} & 
            \textbf{G} & 
            \textbf{H}\\
        \hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It' too long, it's too long, it's too looooooooooooooooooooooog\\
        \end{tabular}
\end{center}


\begin{center}
        \begin{tabular}{|*{7}{c|}>{\raggedright\arraybackslash}p{5.5cm}|}
            \textbf{A} &  
            \textbf{B} &  
            \textbf{C} &  
            \textbf{D} &
            \textbf{E} &               
            \textbf{F} & 
            \textbf{G} & 
            \textbf{H}\\
        \hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It' too long, it's too long,\newline it's too loooooooooooooooooooog\\
        \end{tabular}
\end{center}
\end{document}

makecell包及其同名命令也可能是一个有用的工具:

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape, margin=0.5in]{geometry}
\usepackage{makecell}
\title{ABC}

\begin{document}

\maketitle

\section{First}
\begin{center}
        \begin{tabular}{|*{8}{c|}}
            \textbf{A} &  
            \textbf{B} &  
            \textbf{C} &  
            \textbf{D} &
            \textbf{E} &               
            \textbf{F} & 
            \textbf{G} & 
            \textbf{H}\\
        \hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            \makecell[lt]{It' too long, it's too long,\\ it's too looooooooooooooooooooooog}\\
        \end{tabular}
\end{center}

\end{document}

如果要在表格单元格内自动换行,同时确保表格的宽度与文本宽度完全相同,请使用环境内包中X的类型列:tabularxtabularx

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape, margin=0.5in]{geometry}
\usepackage{tabularx}
\title{ABC}

\begin{document}

\maketitle

\section{First}

        \begin{tabularx}{\textwidth}{|*{7}{c|}>{\raggedright\arraybackslash}X|}
            \textbf{A} &  
            \textbf{B} &  
            \textbf{C} &  
            \textbf{D} &
            \textbf{E} &               
            \textbf{F} & 
            \textbf{G} & 
            \textbf{H}\\
        \hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It' too long, it's too long, it's too looooooooooooooooooooooog It' too long, it's too long, it's too looooooooooooooooooooooog It' too long, it's too long, it's too looooooooooooooooooooooog\\
        \end{tabularx}


\end{document}

相关内容