如何完全刪除一行底部和下一行頂部之間的空間

如何完全刪除一行底部和下一行頂部之間的空間

即使當我嘗試將行間距設為零時,行之間仍然存在輕微的間距。是什麼原因造成的以及如何將此空間設為零?

\documentclass{article}
\usepackage{anyfontsize}

\setlength{\fboxsep}{0cm}  % So that we can see the exact box around some text
\setlength{\fboxrule}{0.1pt}  % Hairline box

\begin{document}

\noindent{\fontsize{1cm}{1cm}\selectfont \fbox{Foo}\\\fbox{Bar}}

\end{document}

行與行之間的空間

答案1

您需要設定\lineskip為 0,但您也指定了 `cm 的基線跳躍,但您的方塊比該值小:

在此輸入影像描述

\documentclass{article}
\usepackage{anyfontsize}



\setlength{\fboxsep}{0cm}  % So that we can see the exact box around some text
\setlength{\fboxrule}{0.1pt}  % Hairline box

\begin{document}
\setlength\lineskip{0pt}
\fontsize{1cm}{.7cm}\selectfont 

\noindent\fbox{Foo}\\\fbox{Bar}


\bigskip

\noindent\fbox{\strut Foo}\\\fbox{\strut Bar}

\end{document}

答案2

設定\setlength\lineskip{0pt}(如大衛的回答)仍然留下了一個小間隙,但是\nointerlineskip(正如芭芭拉對我的問題的評論)完全消除了間隙。

一個使用的工作範例\nointerlineskip

\documentclass{article}
\usepackage{anyfontsize}

\setlength{\fboxsep}{0cm}  % So that we can see the exact box around some text
\setlength{\fboxrule}{0.1pt}  % Hairline box

\begin{document}
    \fontsize{1cm}{0.7cm}\selectfont 

    \noindent\fbox{One} \par \nointerlineskip \noindent\fbox{Two}

    % Or use whitespace instead of par:

    \noindent\fbox{Three} 

    \nointerlineskip
    \noindent\fbox{Four}
\end{document}

結果(放大):

在此輸入影像描述

也可以透過\offinterlineskip在文件部分的開頭放置序言來全域關閉行間跳過。

還值得注意的是,當您用於建立換行符時,它\nointerlineskip不起作用。\\例如,foo \\ \nointerlineskip bar會導致錯誤。

相關內容