![将文本换行放在表格中并逐项列出?](https://linux22.com/image/335155/%E5%B0%86%E6%96%87%E6%9C%AC%E6%8D%A2%E8%A1%8C%E6%94%BE%E5%9C%A8%E8%A1%A8%E6%A0%BC%E4%B8%AD%E5%B9%B6%E9%80%90%E9%A1%B9%E5%88%97%E5%87%BA%EF%BC%9F.png)
我想得到以下效果,而无需手动使用&
和\\
来换行文本(即,所有文本将自动换行)
\documentclass[11pt,letterpaper]{article}
% Make lists without bullets and compact spacing
\renewenvironment{itemize}{
\begin{list}{}{
\setlength{\leftmargin}{1.5em}
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0em}
\setlength{\parsep}{0.25em}
}
}{
\end{list}
}
\begin{document}
\section*{Main-Section}
\subsection*{Sub-Section}
\begin{itemize}
\item \begin{tabular}{@{}ll}
Title: &This is not a title, this is perhaps a title, nobody but you know!\\
&This is not a title, this is perhaps a title, nobody but you know!\\
&This is not a title, this is perhaps a title, nobody but you know!\\
TitleAgain: &This is not a title, this is perhaps a title, nobody but you know!\\
&This is not a title, this is perhaps a title, nobody but you know!\\
&This is not a title, this is perhaps a title, nobody but you know!\\
\end{tabular}
\end{itemize}
\end{document}
答案1
您可以使用tabularx
环境并将所需宽度设置为\linewidth
。然后文本将在X
-column 中自动换行。根据您的使用情况,description
环境可能更方便。代码:
\documentclass[11pt,letterpaper]{article}
% Make lists without bullets and compact spacing
\newenvironment{myitemize}{
\begin{list}{}{
\setlength{\leftmargin}{1.5em}
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0em}
\setlength{\parsep}{0.25em}
}
}{
\end{list}
}
\usepackage{enumitem,tabularx,showframe,calc}
\begin{document}
\section*{Main-Section}
\subsection*{Sub-Section}
\begin{myitemize}
\item
\begin{tabularx}{\linewidth}[t]{@{}lX@{}}
Title: & This is not a title, this is perhaps a title, nobody but
you know! This is not a title, this is perhaps a title,
nobody but you know! This is not a title, this is
perhaps a title, nobody but you know!\tabularnewline
TitleAgain:
& This is not a title, this is perhaps a title, nobody
but you know! This is not a title, this is perhaps a
title, nobody but you know! This is not a title, this
is perhaps a title, nobody but you know!
\end{tabularx}
\end{myitemize}
\begin{description}[font=\normalfont,labelindent=1.5em,%
labelwidth=\widthof{TitleAgain:},leftmargin=!]
\item[Title:] This is not a title, this is perhaps a title, nobody but
you know! This is not a title, this is perhaps a title, nobody but
you know! This is not a title, this is perhaps a title, nobody but
you know!
\item[TitleAgain:] This is not a title, this is perhaps a title,
nobody but you know! This is not a title, this is perhaps a title,
nobody but you know! This is not a title, this is perhaps a title,
nobody but you know!
\end{description}
\end{document}
答案2
您是否尝试过使用 p(段落)模式对齐表格单元格?例如
\documentclass[11pt,letterpaper]{article}
\usepackage[showframe]{geometry}
\begin{document}
I would like to get the following effect without manually using ``\&'' and ``\textbackslash'' to wrap the text (i.e., all the text will be wrapped automatically).
\hspace{1cm}
\begin{table}[!h]
\begin{tabular}{l c p{4in}}
\hline
Title & &Title to the long Text cell\\
\hline
Title&: &This is not a title, this is perhaps a title, nobody but you know!
This is not a title, this is perhaps a title, nobody but you know!
This is not a title, this is perhaps a title, nobody but you know!\\
TitleAgain&: &This is not a title, this is perhaps a title, nobody but you know!
This is not a title, this is perhaps a title, nobody but you know!
This is not a title, this is perhaps a title, nobody but you know!\\
\hline
\end{tabular}
\caption{Solution: Text wrapped using the \texttt{p} (paragraph) alignment.}
\end{table}
\end{document}
答案3
你的意思是这样的吗:
\documentclass[11pt,letterpaper]{article}
\usepackage[showframe]{geometry}
% Make lists without bullets and compact spacing
\renewenvironment{itemize}{
\begin{list}{}{
\setlength{\leftmargin}{1.5em}
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0em}
\setlength{\parsep}{0.25em}
}
}{
\end{list}
}
\newcommand{\wrapit}[2]{%
\addvspace{\baselineskip}
\parbox[t]{2cm}{#1\wrapdelim}%
\hspace*{1em}%
\parbox[t]{\dimexpr \textwidth - \parindent - 2cm - 1em\relax}{#2}%
\par\addvspace{\baselineskip}
}
\newcommand*{\wrapdelim}{:}
% note: just as I defined '\wrapdelim', you could define lengths to make maintaining `\wrapit` more easy to control
\begin{document}
\section*{Main-Section}
\subsection*{Sub-Section}
\begin{itemize}
\item \begin{tabular}{@{}ll}
Title: &This is not a title, this is perhaps a title, nobody but you know!\\
&This is not a title, this is perhaps a title, nobody but you know!\\
&This is not a title, this is perhaps a title, nobody but you know!\\
TitleAgain: &This is not a title, this is perhaps a title, nobody but you know!\\
&This is not a title, this is perhaps a title, nobody but you know!\\
&This is not a title, this is perhaps a title, nobody but you know!\\
\end{tabular}
\end{itemize}
I would like to get the following effect without manually using ``\&'' and ``\textbackslash'' to wrap the text (i.e., all the text will be wrapped automatically).
%\newpage
\wrapit{Title}{I would like to get the following effect without manually using ``\&'' and ``\textbackslash'' to wrap the text (i.e., all the text will be wrapped automatically).}
\wrapit{TitleAgain}{I would like to get the following effect without manually using ``\&'' and ``\textbackslash'' to wrap the text (i.e., all the text will be wrapped automatically).}
I would like to get the following effect without manually using ``\&'' and ``\textbackslash'' to wrap the text (i.e., all the text will be wrapped automatically).
\end{document}