编辑 1:图像应为“三行而不是四行”。
编辑2:可编译代码已更新。
我是 Latex 的新手,我有以下一段模板代码,可以为我的论文提供标题:
\documentclass[headsepline,footsepline,footinclude=false,oneside,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc]{scrbook} % one-sided
\usepackage{graphicx}
\usepackage[ngerman,american]{babel}
\newcommand*{\getUniversity}{University of Earth}
\newcommand*{\getFaculty}{Engineering Department}
\newcommand*{\getDegree}{Computer Science}
\newcommand*{\getSchool}{School of Public Science}
\newcommand*{\getTitle}{This is a Long title that I want to stretch the Margin so that instead of 4 lines, it should only be 3 lines, and the logo at the end won't break}
\newcommand*{\getTitleGer}{This is a Long title that I want to stretch the Margin so that instead of 4 lines, it should only be 3 lines, and the logo at the end won't break}
\newcommand*{\getAuthor}{Author}
\newcommand*{\getDoctype}{Thesis}
\newcommand*{\getSupervisor}{Faculty Professor}
\newcommand*{\getAdvisor}{Faculty Advisr}
\newcommand*{\getSubmissionDate}{\today}
\newcommand*{\getSubmissionLocation}{Somewhere In between}
\begin{document}
\begin{titlepage}
\centering
\includegraphics[height=20mm]{example-image-a}
\vspace{5mm}
{\huge\MakeUppercase{School of \getSchool{} --- \getFaculty{}} \par}
\vspace{5mm}
{\large\MakeUppercase{\getUniversity{}} \par}
\vspace{20mm}
% \vspace{6mm}
{\Large \getDoctype{} in \getDegree{} \par}
\vspace{15mm}
% \vspace{4mm}
{\huge\bfseries \getTitle{} \par}
\vspace{5mm}
{\huge\bfseries \foreignlanguage{ngerman}{\getTitleGer{}} \par}
\vspace{10mm}
\begin{tabular}{l l}
Author: & \getAuthor{} \\
Supervisor: & \getSupervisor{} \\
Advisors: & \getAdvisor{} \\
Submission Date: & \getSubmissionDate{} \\
\end{tabular}
\vfill{}
\includegraphics[height=15mm]{example-image-b}
\end{titlepage}
\end{document}
我有两个问题:
有没有办法增加 \getTitle{} 部分的行边距?我想保留字体大小和 vspace{} 规范。随着标题变长,它很快就会变成 3-4 行。我想将其拉伸到 2-3 行左右。
如果标题太长,作者部分和结尾
faculty_logo
(代码片段中的图像示例 B)会跳转到下一页。有没有办法始终将这两个组件固定在页面底部,而无需转到下一页?
总的来说,我想要 2 个标题,每个标题都有 3 行在代码片段中定义的相同文本长度,并且所有内容都应保留在同一页面上。
答案1
也许一个宏就足够了,它可以产生一个\parbox
突出到边缘的东西:
\documentclass[headsepline,footsepline,footinclude=false,oneside,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc]{scrbook} % one-sided
%---------------------------------------------------------
\newsavebox\scratchbox
\newcommand\boxIntoMargins[4]{%
\savebox\scratchbox{%
\mbox{%
\kern-\dimexpr(#1)\relax
\parbox[b]{\dimexpr((#1)+(#2)+(#3))\relax}{#4}%
}%
}%
\wd\scratchbox=\linewidth
\usebox\scratchbox
}%
%---------------------------------------------------------
\usepackage{graphicx}
\usepackage[ngerman,american]{babel}
\newcommand*{\getUniversity}{University of Earth}
\newcommand*{\getFaculty}{Engineering Department}
\newcommand*{\getDegree}{Computer Science}
\newcommand*{\getSchool}{School of Public Science}
\newcommand*{\getTitle}{%
\boxIntoMargins{1.5cm}{\linewidth}{1.5cm}{%
\centering
This is a Long title that I want to stretch the Margin so that instead of 4 lines, it should only be 3 lines, and the logo at the end won't break%
}%
}
\newcommand*{\getTitleGer}{%
\boxIntoMargins{1.5cm}{\linewidth}{1.5cm}{%
\centering
This is a Long title that I want to stretch the Margin so that instead of 4 lines, it should only be 3 lines, and the logo at the end won't break%
}%
}
\newcommand*{\getAuthor}{Author}
\newcommand*{\getDoctype}{Thesis}
\newcommand*{\getSupervisor}{Faculty Professor}
\newcommand*{\getAdvisor}{Faculty Advisr}
\newcommand*{\getSubmissionDate}{\today}
\newcommand*{\getSubmissionLocation}{Somewhere In between}
\begin{document}
\begin{titlepage}
\centering
\includegraphics[height=20mm]{example-image-a}
\vspace{5mm}
{\huge\MakeUppercase{School of \getSchool{} --- \getFaculty{}} \par}
\vspace{5mm}
{\large\MakeUppercase{\getUniversity{}} \par}
\vspace{20mm}
% \vspace{6mm}
{\Large \getDoctype{} in \getDegree{} \par}
\vspace{15mm}
% \vspace{4mm}
{\huge\bfseries \getTitle{} \par}
\vspace{5mm}
{\huge\bfseries \foreignlanguage{ngerman}{\getTitleGer{}} \par}
\vspace{10mm}
\begin{tabular}{l l}
Author: & \getAuthor{} \\
Supervisor: & \getSupervisor{} \\
Advisors: & \getAdvisor{} \\
Submission Date: & \getSubmissionDate{} \\
\end{tabular}
\vfill{}
\includegraphics[height=15mm]{example-image-b}
\end{titlepage}
\end{document}
使用 Overleaf 编译的截图:
我又忘记调整模板的默认值了。图片b的高度应该是20mm,但还是会跳到第二页。有没有办法让它一直保持在一页上?
这个答案的初始版本的作者猜测,没有办法总是将内容放在一页上,因为一页上容纳太多文本的条件总是可以通过增加更多文本来满足。;-) 他认为尝试自动调整内容以增加内容放在一页上的机会可能不值得付出努力。
您可能可以将标题页的内容放入单独的内容中,其中的内容可能超出纸张的尺寸,并结合使用来自包 graphicxs 的\newsavebox
命令和缩小框以适合纸张的命令。\scalebox
\usebox
或者将标题页放在单独的 .tex 文档中,然后从中创建单独的 .pdf 文件,再将其包含在主文档中,通过\includegraphics
缩小尺寸以适合主文档的纸张大小。在单独的 .tex 文档中,一个装有标题页的盒子在调整和后运出,该盒子的尺寸超出了文档的纸张尺寸\(pdf)pagewidth
。\(pdf)pageheight
以下
可能是以这种方式处理问题的概述:
\documentclass{article}
\newbox\BoxWithTitlepage
\newcommand\ShipoutAsPage[1]{%
\begingroup
\setbox\BoxWithTitlepage=\vbox{%
\hrule height 0pt
#1\ifvmode\else\expandafter\endgraf\fi
\hrule height 0pt
}%
\csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\wd\BoxWithTitlepage}%
\csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\wd\BoxWithTitlepage}%
\csname @ifundefined\endcsname{pageheight}{}{\pageheight=\ht\BoxWithTitlepage
\advance\pageheight\dp\BoxWithTitlepage}%
\csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\ht\BoxWithTitlepage
\advance\pdfpageheight\dp\BoxWithTitlepage}%
\shipout\vbox{\kern-1truein\hbox{\kern-1truein\box\BoxWithTitlepage}}%
\endgroup
}%
\begin{document}
\ShipoutAsPage{%
% Content of your titlepage
% Content of your titlepage
% Content of your titlepage
% Content of your titlepage
}%
\end{document}
但不建议这么做的理由如下:
- 这样,您就无法轻易地从标题页建立指向文档其他地方的超链接。
- 缩放后看起来不太好,因为字体不再是其自然大小。
- 规则/线条(例如,使用
tikzpicture
环境创建的表格或图像的规则/线条)在将事物缩放到较小尺寸时可能会变得太细,因此可能无法打印。
因此,您最好“手动”调整一下,例如,将标题页的字体区域稍微扩大到纸张底部,并将字距稍微向上调整。以下是一个“快速而粗糙”的解决方案,但可能可以实现目的:
\documentclass[headsepline,footsepline,footinclude=false,oneside,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc]{scrbook} % one-sided
%---------------------------------------------------------
\newsavebox\scratchbox
\newcommand\boxIntoMargins[4]{%
\savebox\scratchbox{%
\mbox{%
\kern-\dimexpr(#1)\relax
\parbox[b]{\dimexpr((#1)+(#2)+(#3))\relax}{#4}%
}%
}%
\wd\scratchbox=\linewidth
\usebox\scratchbox
}%
%---------------------------------------------------------
\usepackage{graphicx}
\usepackage[ngerman,american]{babel}
\newcommand*{\getUniversity}{University of Earth}
\newcommand*{\getFaculty}{Engineering Department}
\newcommand*{\getDegree}{Computer Science}
\newcommand*{\getSchool}{School of Public Science}
\newcommand*{\getTitle}{%
\boxIntoMargins{1.5cm}{\linewidth}{1.5cm}{%
\centering
This is a Long title that I want to stretch the Margin so that instead of 4 lines, it should only be 3 lines, and the logo at the end won't break%
}%
}
\newcommand*{\getTitleGer}{%
\boxIntoMargins{1.5cm}{\linewidth}{1.5cm}{%
\centering
This is a Long title that I want to stretch the Margin so that instead of 4 lines, it should only be 3 lines, and the logo at the end won't break%
}%
}
\newcommand*{\getAuthor}{Author}
\newcommand*{\getDoctype}{Thesis}
\newcommand*{\getSupervisor}{Faculty Professor}
\newcommand*{\getAdvisor}{Faculty Advisr}
\newcommand*{\getSubmissionDate}{\today}
\newcommand*{\getSubmissionLocation}{Somewhere In between}
\begin{document}
\begin{titlepage}
\enlargethispage{1cm}%
\hrule height 0mm
\kern-.5cm
\centering
\includegraphics[height=20mm]{example-image-a}
\vspace{5mm}
{\huge\MakeUppercase{School of \getSchool{} --- \getFaculty{}} \par}
\vspace{5mm}
{\large\MakeUppercase{\getUniversity{}} \par}
\vspace{20mm}
% \vspace{6mm}
{\Large \getDoctype{} in \getDegree{} \par}
\vspace{15mm}
% \vspace{4mm}
{\huge\bfseries \getTitle{} \par}
\vspace{5mm}
{\huge\bfseries \foreignlanguage{ngerman}{\getTitleGer{}} \par}
\vspace{10mm}
\begin{tabular}{l l}
Author: & \getAuthor{} \\
Supervisor: & \getSupervisor{} \\
Advisors: & \getAdvisor{} \\
Submission Date: & \getSubmissionDate{} \\
\end{tabular}
\vfill{}
\includegraphics[height=20mm]{example-image-b}
\end{titlepage}
\end{document}
如果比例 ⟨height-of-top-margin⟩:⟨height-of-bottom-margin⟩ 不是 1:1,您可能需要做更多的计算来确保在垂直方向上向上调整字距,同时向下扩大字体区域时,该比例仍然保持不变。
如果比例 ⟨width-of-margin-at-the-left⟩:⟨width-of-margin-at-the-right⟩ 不是 1:1,你可能需要做更多的计算来确保
\boxIntoMargins{<amount of horizontal space that sticks into left margin>}%
{\linewidth}%
{<amount of horizontal space that sticks into right margin>}%
{...}%
该比例得以保留。
也许用这条线
{\huge\MakeUppercase{School of \getSchool{} --- \getFaculty{}} \par}
看起来会很好看,因为这样如果在第一个破折号之前出现换行符,并且表示院系的整个字符串单独放在一行上,那么在排列时就会很好看。在后面附加一个破折号,\getFaculty{}
这样院系字符串就嵌套在两个破折号之间。;-)
顺便说一句:你的例子的代码让我想起了封面和标题页,带有剪贴簿,标题页后有不需要的空白页。也许您会在那里找到一些有用的见解。