
我在 LyX 中擁有的是這樣的:
我在序言中加入了這一行:
\global\setlength{\parskip}{20pt}
因此,我期望每行之間有 20pt 的間距。然而,這不會發生在 Parbox 內。我的輸出:
問題:我應該如何實現上面第 3 行和第 4 行之間的 20pt 間距?我希望這能夠在全球範圍內完成(即在我的文件中的所有 Parbox 中)。
LaTeX 程式碼(從 LyX 匯出):
%% LyX 2.2.3 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{calc}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\global\setlength{\parskip}{20pt}
\makeatother
\usepackage{babel}
\begin{document}
1. Hi
2. Hi
\noindent{\fboxrule 3pt\fboxsep 6pt\fbox{\parbox[t]{1\columnwidth - 2\fboxsep - 2\fboxrule}{%
3. Hi
4. Hi%
}}}
\end{document}
答案1
您可以在使用者指定的命令中新增以下內容:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\setlength{\parskip}{20pt}
\let\oldparbox\parbox
\renewcommand\parbox[3][t]{\oldparbox[#1]{#2}{\setlength{\parskip}{20pt}#3}}
\makeatother
編輯:下一個“PS”是錯誤的:(參見大衛的評論)
PS:我真的不知道 parbox 中的預設可選參數是否是t
,但我查找了它,現在我知道它是。「粗體」之間的這句話不正確
我的藉口:我剛剛“谷歌搜索”並首先得到以下結果:
我看到了帶有標題的鏈接\parbox
,只是從最後兩行讀到了上面的錯誤句子...
所以,我吸取了教訓......始終仔細檢查您的來源不要僅僅相信你在谷歌上看到的“距離”
答案2
我知道這不是對你的問題的直接回答,而且肯定有些矯枉過正。但是,如果您想在不移動文字的情況下繪製方框(在您的範例中,3 和 4 向左移動了一點),您始終可以使用 TikZ 疊加。
\documentclass[english]{article}
\usepackage{calc}
\usepackage{tikzpagenodes}
\usetikzlibrary{fit}
\newcommand{\tikznode}[2]{\tikz[remember picture,baseline=(#1.base)]{\node(#1)[inner sep=0pt]{#2};}}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\global\setlength{\parskip}{20pt}
\makeatother
\begin{document}
1. Hi
2. Hi
3. Hi\tikznode{3}{\strut}
4. Hi\tikznode{4}{\strut}%
\begin{tikzpicture}[overlay,remember picture]
\node [fit=(current page text area.west|-4.south) (current page text
area.east|-3.north),draw,ultra thick,rectangle]{};
\end{tikzpicture}
\end{document}
如果您只想繪製這些框,這無疑是一種矯枉過正,但如果您想做更奇特的事情,這可能是合理的選擇。
答案3
因為你似乎想要\parskip
在每一個\parbox
:
\documentclass{article}
\newlength{\normalparskip}
\setlength{\normalparskip}{20pt}
\AtBeginDocument{\setlength{\parskip}{\normalparskip}\setlength{\parindent}{0pt}}
\makeatletter
\g@addto@macro{\@parboxrestore}{\setlength{\parskip}{\normalparskip}}
\makeatother
\newcommand{\framedparbox}[2][c]{%
\noindent
\begingroup
\setlength{\fboxrule}{3pt}%
\setlength{\fboxsep}{6pt}%
\fbox{\parbox[#1]{\dimexpr1\columnwidth - 2\fboxsep - 2\fboxrule}{#2}}%
\endgroup
}
\begin{document}
1. Hi
2. Hi
\framedparbox[t]{%
3. Hi
4. Hi%
}
\end{document}