字母线、显式换行和悬挂缩进

字母线、显式换行和悬挂缩进

我需要结合字母线、明确的换行符和悬挂缩进,以使任何文本块最终长度超过一行排版。

为了实现半自动文本生成,我更愿意只处理(自定义)换行命令(\lb在示例中)。

使用时,\newline文字可以正确显示(不会被下一行覆盖),但整个文本除第一行之外的所有内容都会被悬挂。

悬挂\par缩进是正确的,但对于受到字母影响的行则不正确:

\documentclass[11pt,a5paper]{article}

\usepackage[showframe]{geometry}


\usepackage{lettrine}

%\newcommand{\lb}{\newline}
\newcommand{\lb}{\par}

\setlength{\leftskip}{5cm}
\setlength{\parindent}{-5cm}



\begin{document}

A pretty short line of regular text\lb
A pretty short line of regular text\lb
A pretty short line of regular text\lb
\lettrine{A}{} short line with lettrine\lb
A pretty short line with lettrine\lb
A pretty short line with lettrine\lb
A pretty short line of regular text\lb
A pretty short line of regular text but way too long to be on one line, so we need to break it\lb
A pretty short line of regular text\lb

\end{document}

我正在寻找一种方法,让字母和普通文本全部左对齐较长的行需要进行负向缩进,如下所示:

期望结果

答案1

姆韦

不确定您到底想做什么,但是没有大写字母的行就足够了\everypar{\hangindent5cm},当然每行都必须是一个段落。

如果您不想在某些行之后出现悬挂缩进,请添加\handafter

所有这些都不适用于 lettrines 段落,因为它们已经有固定的参数,但通过\lettrine 选项,您可以模拟\hangindent并以多种方式调整 lettrine 的位置和大小。我在 MWE 中使用了其中一些选项来展示一些可能性。

似乎您还希望将多行附加到同一个字母。 然后,它们必须位于同一段落中并使用\newline。 这将不允许每行可能的长行都挂起缩进,而只能为整个段落模拟它。

为了简单起见,MWE 下面\par只显示虚拟文本,而不是空行和宏:

\documentclass[11pt,a5paper]{article}
\usepackage{geometry}
\usepackage{lettrine,lipsum,xcolor}
\setlength{\parindent}{0pt}
% dummy text definitions
\def\kantreason{our knowledge  begins with the senses, 
proceeds then to the understanding, and ends with reason. 
There is nothing higher than reason.}
\def\shortext{A pretty short line of regular text.}
\def\droptext{Another short line with lettrine.}
\begin{document}
{\par\setlength{\parskip}{1ex}
\everypar{\hangindent5cm}
\shortext
\lettrine[lines=5,findent=-20pt,slope=.5em]{A}{ll} 
\kantreason 
\newline  \droptext \newline \droptext
\par\shortext
\par All \kantreason
\par\shortext
\par All \kantreason
\lettrine[loversize=-.1,lraise=.5,lines=3,lhang=0, 
findent=-5pt,nindent=2cm]{A}{ll} \kantreason
\par\shortext
\par\hangafter3\shortext\shortext\shortext\shortext
\shortext\shortext\shortext\shortext\shortext 
\par} % group must end with \par!!!
\end{document}

答案2

而不是使用lettrine,您可以调整\parshape环绕在信件周围。这样就\newline可以正常工作了。

在此处输入图片描述

\documentclass{article}

\usepackage{lettrine,graphicx}

\newcommand{\lb}{\newline}

% https://tex.stackexchange.com/q/127504/5764
\makeatletter
\def\newparshape{\parshape\@npshape0{}}
\def\@npshape#1#2#3{\ifx\\#3\expandafter\@@@npshape\else\expandafter\@@npshape\fi
  {#1}{#2}{#3}}
\def\@@npshape#1#2#3#4#5{%
  \ifnum#3>\z@\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
  {\expandafter\@@npshape\expandafter{\the\numexpr#1+1\relax}{#2 #4 #5}{\numexpr#3-1\relax}{#4}{#5}}%
  {\@npshape{#1}{#2}}}
\def\@@@npshape#1#2#3{#1 #2 }
\makeatother

\begin{document}

\raggedright
A pretty short line of regular text\lb
A pretty short line of regular text\lb
A pretty short line of regular text\lb
\newparshape{4}{0pt}{\linewidth}{1}{2.5em}{\dimexpr\linewidth-2.5em}{1}{0pt}{\linewidth}\\
\raisebox{\dimexpr-\height+.6\baselineskip}[0pt][0pt]{%
  \resizebox{!}{1.6\baselineskip}{A}}pretty short line with lettrine\lb
A pretty short line with lettrine\lb
A pretty short line with lettrine\lb
A pretty short line of regular text\lb
A pretty short line of regular text but way too long to be on one line, so we need to break it\lb
A pretty short line of regular text\lb

\end{document}

在更大的文档中,你可以\lettrine为每个字母定义一个“ ”,例如:

\newcommand{\LettrineA}{%
  \newparshape{4}{0pt}{\linewidth}{1}{2.5em}{\dimexpr\linewidth-2.5em}{1}{0pt}{\linewidth}\\
  \raisebox{\dimexpr-\height+.6\baselineskip}[0pt][0pt]{%
    \resizebox{!}{1.6\baselineskip}{A}}%
}

\newcommand{\LettrineB}{%
  % ...
}

答案3

事实证明lettrine.sty可以轻松修改以允许悬挂段落:

\noindent用(文件中唯一出现的)注释掉该行,用其他名称保存并\indent在换行符处提供将产生与问题屏幕截图中完全相同的结果。

\documentclass[11pt,a5paper]{article}

\usepackage[showframe]{geometry}

\usepackage{lettrineHANGING}

\newcommand{\lb}{\newline\indent}
%\newcommand{\lb}{\par}

\setlength{\leftskip}{5cm}
\setlength{\parindent}{-5cm}

\begin{document}

A pretty short line of regular text\lb
A pretty short line of regular text\lb
A pretty short line of regular text%\lb
\lettrine{A}{} short line with lettrine\lb
A pretty short line with lettrine\lb
A pretty short line with lettrine\lb
A pretty short line of regular text\lb
A pretty short line of regular text but way too long to be on one line, so we need to break it\lb
A pretty short line of regular text\lb

\end{document}

可能还有更优雅的解决方案,但这个解决方案看起来很强大,并且不需要人工干预。

相关内容