![固定页脚以在文档内有不同的行距](https://linux22.com/image/434915/%E5%9B%BA%E5%AE%9A%E9%A1%B5%E8%84%9A%E4%BB%A5%E5%9C%A8%E6%96%87%E6%A1%A3%E5%86%85%E6%9C%89%E4%B8%8D%E5%90%8C%E7%9A%84%E8%A1%8C%E8%B7%9D.png)
我想改变 LaTeX 文档中的行距。我希望页脚、标题和文档的其他部分采用半行距,但正文采用双行距。
setspace
我的解决方案是在\doublespacing
文本中使用,并在页脚中为每个文本指定它。类似于此线程:https://tex.stackexchange.com/a/542102
\documentclass[fontsize = 12pt]{scrreprt}
\usepackage{lmodern} % for different font style
\usepackage{lipsum} % for dummy text
\usepackage{tabularx} % for tabulars
\usepackage{booktabs} % for tabular functions
\usepackage{scrlayer-scrpage} % for modifying footer
\clearpairofpagestyles % remove standard style (removes default pagenumbering)
\usepackage[onehalfspacing]{setspace} % change linespace to 2
% defining the footer
\newcommand{\footerON}
{
\ifoot[ % footer for even pages
\onehalfspacing
\begin{tabularx}{\textwidth}{m{0.79\textwidth}Xr} % create tabular over textwidth
\midrule % horizontal line over footer
A long title of my document which stretches over two lines created by KarateKlaus & &
\thepage % pagenumbering on the right
\end{tabularx}
\doublespacing
]
{ % same footer for odd pages
\onehalfspacing
\begin{tabularx}{\textwidth}{m{0.79\textwidth}Xr}
\midrule
A long title of my document which streches over two lines created by KarateKlaus & &
\thepage
\end{tabularx}
\doublespacing
}
}
\newcommand{\footerOFF}{\ifoot[]{}}
\begin{document}
\footerON
\chapter{multiline chaptertitle to test the linespaceing}
\doublespacing
\lipsum[1-1]
\par
\onehalfspacing
\section{multiline sectiontitle to test the linespaceing in a section}
\doublespacing
\lipsum[1-3]
\par
\onehalfspacing
\end{document}
这种方法的问题似乎是页脚上方的水平线在整个文档中的高度不一致。当段落在下一侧继续时,整个页脚会稍微向下移动。
有没有办法固定页脚或者至少解决我的问题?
答案1
题外话:代码中关于的注释\ifoot
是错误的。语法\ifoot
是
\ifoot[<content for page style plain.scrheadings>]{<content for page style scrheadings>}
还有一个简短版本
\ifoot*{<content for both page styles plain.scrheadings and scrheadings>}
您的代码中之前有一个虚假空格\onehalfspacing
。您必须注释掉这些空格:
\ifoot*{% <- removes spurious space!
\onehalfspacing
...
\doublespacing
}
但你应该从中删除\onehalfspacing
和。使用\doublespacing
\ifoot
\KOMAoptions{onpsinit=\onehalfspacing}
您将获得页眉和页脚所需的间距。
\documentclass[fontsize = 12pt,
headheight=24pt,footheight=61pt% avoids the warning regarding head height and foot height
]{scrreprt}
\usepackage{lmodern}
\usepackage{lipsum}% only for dummy text
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles% removes default header and footer content for both page styles plain.scrheadings and scrheadings
\usepackage[onehalfspacing]{setspace}
\KOMAoptions{onpsinit=\onehalfspacing}% header and footer use \onehalfspacing
% defining the footer
\newcommand{\footerON}
{%
\ifoot*{% <- removes spurious space!
\begin{tabularx}{\textwidth}{m{0.79\textwidth}>{\raggedleft}X}
\midrule
A long title of my document which stretches over two lines created by KarateKlaus &
\pagemark
\end{tabularx}
}%
}
\newcommand{\footerOFF}{\ifoot*{}}
\begin{document}
\footerON
\chapter{multiline chaptertitle to test the linespaceing}
\doublespacing
\lipsum[1]
\par
\onehalfspacing
\section{multiline sectiontitle to test the linespaceing in a section}
\doublespacing
\lipsum[1-3]
\par
\onehalfspacing
\end{document}
但也许你可以使用
\documentclass[fontsize = 12pt,
headheight=24pt,footheight=61pt% avoids the warning regarding head height and foot height
]{scrreprt}
\usepackage{lmodern}
\usepackage{lipsum}% only for dummy text
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles% removes default header and footer content for both page styles plain.scrheadings and scrheadings
\usepackage[doublespacing]{setspace} % change linespace
\AddtoDoHook{heading/begingroup}{\useonehalfspacing}% headings should use \onehalfspacing
\newcommand*\useonehalfspacing[1]{\onehalfspacing}
\KOMAoptions{onpsinit=\onehalfspacing}% header and footer use \onehalfspacing
% defining the footer
\newcommand{\footerON}
{%
\ifoot*{% <- removes spurious space!
\begin{tabularx}{\textwidth}{m{0.79\textwidth}>{\raggedleft}X}
\midrule
A long title of my document which stretches over two lines created by KarateKlaus &
\pagemark
\end{tabularx}
}%
}
\newcommand{\footerOFF}{\ifoot*{}}
\begin{document}
\footerON
\chapter{multiline chaptertitle to test the linespaceing}
\lipsum[1]
\section{multiline sectiontitle to test the linespaceing in a section}
\lipsum[1-3]
\end{document}