我在设置一个简单的标题页时遇到了麻烦。
一些水平线没有画在正确的位置,一条线在另一条线的上面(见下面的预览)。
我想在页面四周添加白色边框,打印机无法打印背景颜色。
我想在整个页面周围添加一条细黑线(矩形框),界定背景颜色和白色边框。
这是 MWE 代码:
\documentclass[letterpaper]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{microtype,lmodern}
\usepackage{anysize}
\marginsize{1.5in}{1in}{0.5in}{0.5in}
\usepackage{xcolor}
\definecolor{backgroundcolor}{RGB}{160,180,200}
\usepackage{graphicx}
\usepackage{here}
\usepackage{afterpage}
\newcommand*{\maintitle}{\begingroup
\pagecolor{backgroundcolor}
\centering
\newlength{\titlelength}
\settowidth{\titlelength}{\Huge\scshape Some Main Title}
\vspace*{\baselineskip}
\rule{\titlelength}{1.6pt} \vspace*{-\baselineskip}\vspace*{2pt}
\rule{\titlelength}{0.4pt} \\[\baselineskip]
{\Huge\scshape Some Main Title} \\[\baselineskip]
{\large\slshape Subtitle} \\[0.2\baselineskip]
\rule{\titlelength}{0.4pt} \vspace*{-\baselineskip}\vspace{3.2pt}
\rule{\titlelength}{1.6pt} \\[4\baselineskip]
{\Large\scshape Name} \\
\vfill
{\large\scshape Version Number}
\par
\endgroup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{titlepage}
\maintitle
\end{titlepage}
\end{document}
本期预览:
如您所见,水平线应该一条一条堆叠在一起,并且与主标题的长度完全相同。
我该如何修复和简化上述代码,并在其外侧添加一个带有白色边框的矩形框架?
答案1
太棒了!我找到了一种使用包添加漂亮框架的简单方法tikz
:
\documentclass[letterpaper]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{microtype,lmodern}
\usepackage{anysize}
\marginsize{1.5in}{1in}{0.5in}{0.5in}
\usepackage{xcolor}
\definecolor{backgroundcolor}{RGB}{160,180,200}
\usepackage{graphicx}
\usepackage{here}
\usepackage{afterpage}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*{\maintitle}{\begingroup
\pagecolor{backgroundcolor}
\centering
\newlength{\titlelength}
\settowidth{\titlelength}{\Huge\scshape Some Main Title}
\vspace*{\baselineskip}
\rule{\titlelength}{1.6pt} \\ \vspace*{-\baselineskip}\vspace*{2pt}
\rule{\titlelength}{0.4pt} \\[\baselineskip]
{\Huge\scshape Some Main Title} \\[\baselineskip]
{\large\slshape Subtitle} \\[0.2\baselineskip]
\rule{\titlelength}{0.4pt} \\ \vspace*{-\baselineskip}\vspace{3.2pt}
\rule{\titlelength}{1.6pt} \\[4\baselineskip]
{\Large\scshape Name} \\
\vfill
{\large\scshape Version Number}
\par
\endgroup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{titlepage}
\maintitle
\begin{tikzpicture}[remember picture, overlay]
\draw[line width = 0.25pt,color = black] ($(current page.north west) + (0.75in,-0.25in)$) rectangle ($(current page.south east) + (-0.25in,0.25in)$);
\draw[line width = 1in,color = white] ($(current page.north west) + (0.25in,0.25in)$) rectangle ($(current page.south east) + (0.25in,-0.25in)$);
\draw[line width = 0.25pt,color = black] ($(current page.north west) + (1in,-0.5in)$) rectangle ($(current page.south east) + (-0.5in,0.5in)$);
\end{tikzpicture}
\end{titlepage}
\end{document}
预览: