
我想在使用時格式化對話文本對話包裹。我已經將揚聲器加粗了,但無法設定演講者文字的格式。我想讓文字放在一個盒子裡(沒有縮進)
使用以下腳本時:
\documentclass{article}
\usepackage{dialogue}
% bold the speaker name
\renewcommand*\DialogueLabel[1]{%
\scshape\textbf{#1}:\hfil
}
\begin{document}
\begin{dialogue}
\speak{Marie} Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
\speak{Marine} What?
\end{dialogue}
我得到以下結果,其中段落的第二行與第一行不對齊:
我想要的是以下格式(斜體和引號是可選的):
非常感謝!
答案1
為了達到你想要的效果,我認為你需要做的是重新定義對話環境,以便將\labelwidth
設定為最長角色名稱的寬度,並將 設定為恰好加上(的寬度)\leftmargin
的值.\labelsep
0.5em
您可以使用calc
套件的\widthof{...}
命令來確定最長字元名稱的長度。下面,我假設它是“Marina”,但如果您的角色名稱較長,則需要\setlength{\widestname}{...
適當更改命令。
例如:
\documentclass{article}
\usepackage[T1]{fontenc} % necessary for bold small caps
\usepackage{setspace} % for double spacing
\usepackage{dialogue}
\usepackage{calc} % to measure width of widest name
\usepackage{lipsum}% dummy text
\renewcommand*\DialogueLabel[1]{%
\scshape\textbf{#1}:\hfil
}
% set width of widest name
\newlength{\widestname}
\setlength{\widestname}{%
\widthof{\textbf{\textsc{Marina}}:}
}
% redefine dialogue environment to use new parameters
\makeatletter
\renewenvironment{dialogue} {%
\begin{list}{} {%
\setlength\itemsep{\z@ \@plus .5ex}%
\setlength{\parsep}{\parskip}%
\setlength{\rightmargin}{0pt}% no indentation on right; change this if you wish
\setlength{\labelwidth}{\widestname}% set label to widest width
\setlength{\labelsep}{0.5em}% space between (longest) name and text
\setlength{\leftmargin}{\labelwidth}% set margin on left to same width
\addtolength{\leftmargin}{\labelsep}% plus the label sep
\defcommand\speak [1] {\item[{##1}]}% define speak command
\let\makelabel\DialogueLabel
}%
\PreDialogue\relax
}{%
\end{list}%
}
\makeatother
\begin{document}
\doublespacing
\lipsum[1][3-9]
\begin{dialogue}
\speak{Maria} \lipsum[2][1-2]
\speak{Marina} \lipsum[1][1-3]
\end{dialogue}
\end{document}
這給出了這個輸出。
如果您還想在每個對話周圍使用斜體和引號,我認為您需要使用稍微不同的語法。您可以變更 的定義以\speak
採用兩個參數,並將第二個參數放在斜體和引號中。也就是說,更改上面的\renewenvironment
行dialogue
:
\defcommand\speak [1] {\item[{##1}]}%
進入這個:
\defcommand\speak[2]{\item[{##1}] {\itshape ``{##2}''}}%
然後你必須像這樣寫對話,用大括號括住名稱和實際的對話文字:
\speak{Maria}{Nam dui ligula, fingilla \ldots}
\speak{Marina}{Lorem ipsum dolor \dots}
你會得到這個。
從風格上來說,我還可以考慮將名稱與文字右對齊:
\defcommand\speak[2]{\item[\hfill {##1}] {\itshape ``{##2}''}}%
對話包就沒那麼複雜。此時你基本上已經重寫一半了;您可能會考慮不使用它並使用\enuitem
或類似的套件來設定對話,但這是一個單獨的主題。
(看起來我將“Marie”更改為“Maria”;哦,好吧,我認為這對於演示解決方案並不重要。)