在对齐段落前添加文本

在对齐段落前添加文本

如何在对齐段落之前添加文本?

例如,我想要一个类似这样的段落

Aside:  Lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum

我目前有以下命令

\newcommand{\aside}[1]{
     \underline{Aside}:\par
     \begingroup
     \leftskip4em
     \rightskip\leftskip
     {#1}
     \par
}

但段落在“Aside:”后跳过了一行。是否有我不知道的更简单的命令?

答案1

在命令定义中,如果后面asidepar“aside”一词,则要求后面的文本以新行开始。看看下面的解决方法是否能达到您想要的效果:

在此处输入图片描述

\documentclass{article}
\newcommand{\aside}[1]{\par\medskip\noindent%
     \underline{Aside}:\hfill
     \begin{minipage}[t]{\dimexpr\linewidth-8em\relax}
        #1
     \end{minipage}\hspace{4em}\mbox{}\par\medskip
                        }

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}  % for dummy text filler

\begin{document}
\lipsum[11]
\aside{Lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum
        lorem ipsum lorem ipsum lorem ipsum lorem ipsum}
\lipsum[12]
\end{document}

编辑:现在已上传正确的图像和代码。抱歉造成不便。

答案2

您可以使用list具有适当参数的环境:

\documentclass{article}
\newcommand{\aside}[1]{
    \begin{list}
    {\underline{Aside:}\hfill}
    {
        \labelsep=0pt
        \labelwidth=4em
        \leftmargin=\labelwidth
        \rightmargin=\labelwidth
    }
        \item #1
    \end{list}
}
\begin{document}
Lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum

\aside{%
Lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum%
}

Lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum 
lorem ipsum lorem ipsum lorem ipsum
\end{document}

在此处输入图片描述

答案3

使用enumitem,定义自定义description环境很简单:

\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum}

\begin{document}

\lipsum[10]

\begin{description}[labelwidth=3em, leftmargin= 4em, rightmargin=4em, itemindent=0pt, nosep, font=\normalfont]
\item[\hspace*{-\fontdimen2\font}\underline{Aside}:]
  \lipsum[11]
\end{description}

\lipsum[1]

\end{document} 

在此处输入图片描述

答案4

五种简单方法(无特定顺序):

\documentclass{article}
\usepackage{tabulary,tabularx,eqlist}
\usepackage{lipsum}
\parskip1em\parindent0pt
\begin{document}

\lipsum[1][1-3] % dummy text 

% method 1
\hangindent4em\makebox[4em][l]{Aside:}\lipsum[1][1-3]

% method 2
\begin{tabulary}{\linewidth}{@{}lL@{}}
Aside: & \lipsum[1][1-3]\\
\end{tabulary}

% method 3
\begin{tabularx}{\linewidth}{@{}lX@{}}
Aside: & \lipsum[1][1-3]\\
\end{tabularx}


% method 4
\makebox[4em][l]{Aside:}\parbox[t]{\dimexpr\linewidth-4em}{\lipsum[1][1-3]}


% method 5 
\begin{eqlist}
\item[Aside:] \lipsum[1][1-3]
\item[Longer label:] \lipsum[1][1-3]
\end{eqlist}

\lipsum[1][1-3] % dummy text 

\end{document}

相关内容