更改 .sty 中的边距

更改 .sty 中的边距

我正在尝试更改输入 .sty 中的边距。我尝试为第一页和第二页设置不同的边距。我设法更改了边距,但第二页中的第一个段落的边距与第一页的边距一样宽,因为 latex 在放置段落之前会生成该段落。有没有办法自动为第一页设置特定的段落框来防止这种情况发生,或者还有其他解决方法吗?

非常感谢

% Load Packages 
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage[hidelinks]{hyperref}
\usepackage[absolute]{textpos}
\usepackage{ifthen}
\usepackage{fancyhdr}
\usepackage{tikz} 
\usepackage{afterpage}



% Define Dark Blue Color, Logo, and Signature Files
\definecolor{XXXblue}{RGB}{0,0,153}
\providecommand\signature{RandomSig}
\providecommand\XXXlogo{RandomLogo}


% Define Letterhead Content
\providecommand\dept{A Really Great Place}
\providecommand\deptaddress{A Subdivision of this Place \\
                        The first address line \\
                        The second address line \\
                        The third address line }
\providecommand\deptphone{123-456-7890 \\ Fax: 123-456-7890}
\providecommand\college{A Really Great Place}
\providecommand\eeo{Doing Very Interesting Things}
\providecommand\myname{Random Person \\
                   Director of Randomness \\
                   Email: \href{[email protected]}      {[email protected]}}
\providecommand\date{\today}
\providecommand\toName{Dear \toName}
\providecommand\toAddress{}
\providecommand\closing{Very Sincerely,}


% Header and Footer
\thispagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[L]{%
\begin{textblock*}{2in}[2in,1in](1in, 1.5in)
    \includegraphics[width=2in]{\XXXlogo}
\end{textblock*}
\usetikzlibrary{calc}
\begin{tikzpicture}[remember picture, overlay]
    \draw[color=XXXblue,line width=0.7pt] (current page.north west)+ (1.18in,-1.0in) -- ($(-0.625in,-1.00in)+(current     page.north                east)$);
\end{tikzpicture}
\begin{textblock*}{2in}(3.36in, 2.18in)
    \scriptsize\color{XXXblue} \textbf{\dept}
\end{textblock*}
\begin{textblock*}{2in}(5.33in, 2.18in)
    \scriptsize\color{XXXblue} \deptaddress
\end{textblock*}
\begin{textblock*}{1in}(7.30in, 2.18in)
    \scriptsize\color{XXXblue} \deptphone
\end{textblock*}
}
\fancyfoot[L]{%
\begin{textblock*}{1.5in}(1.58in,10.40in)
    \scriptsize\color{XXXblue} \college
\end{textblock*}
\begin{textblock*}{2in}(6.60in,10.40in)
    \tiny\color{XXXblue} \eeo
\end{textblock*}    
}
\fancypagestyle{plain}{%
\setlength{\topmargin}{1in}
\setlength{\oddsidemargin}{1in}%
\setlength{\evensidemargin}{1in}%
\setlength{\textheight}{9.0in}%
\fancyhead{}%
\renewcommand{\headrulewidth}{0pt}%
}


% Insert line between paragraphs and don't indent first line
\setlength{\parindent}{0pt}
\setlength{\parskip}{0.8\baselineskip}
\pagestyle{empty}





\interlinepenalty 10000
\setlength{\topmargin}{1.5in}%
\setlength{\textheight}{6.0in}%
\setlength{\oddsidemargin}{1in}%
\setlength{\evensidemargin}{1in}%

\AtBeginDocument{%
\date \\ \\
\ifx\toName\@empty \else \toName\\ \fi
\ifx\toAddress\@empty \else \toAddress\\ \ \\ \fi
\toName \\ \newline
}




      \afterpage{%
      \setlength{\global\topmargin}{1in}%
      \setlength{\global\oddsidemargin}{1in}%
      \setlength{\global\evensidemargin}{1in}%
      \setlength{\global\hsize}{6.5in}%
      }%    





\AtEndDocument{%
\newline \newline
\closing \\ \\
\includegraphics[width=1.5in]{\signature} \\
\myname
}

和 tex 文件

\documentclass{article}

\input{newStyle.sty}
\usepackage{lipsum}

\def\date{\today}
\def\toName{Some Really Important People} 
\def\toAddress{Their Address \\ A place, Somewhere 55555}



\begin{document} 

\lipsum[0-9]

\end{document}

答案1

这是您的代码的一个稍微干净一些的版本。至少它编译时没有错误。它用于changepage调整第一页的页边距。但是,您必须管理分页符并恢复信件正文中的页边距。至少,我目前找不到避免这种情况的方法。

顶部/底部边距不需要调整 - 我们只需在第一页上留出垂直空间以放置信头即可。因此问题在于左/右边距。就我个人而言,我认为最好不要更改这些,而是​​始终保持一致的文本宽度。

\documentclass[letterpaper]{article}
% Load Packages
\usepackage{geometry}
  \geometry{textwidth=6.5in, top=1in, bottom=1in}
\usepackage{xcolor}
\usepackage[demo]{graphicx}
\usepackage[hidelinks]{hyperref}
\usepackage{ifthen}
\usepackage{fancyhdr}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usepackage{changepage}

% Define Dark Blue Color, Logo, and Signature Files
\definecolor{XXXblue}{RGB}{0,0,153}
\newcommand\signature{RandomSig}
\newcommand\XXXlogo{example-image-a}

% Define Letterhead Content
\newcommand\dept{A Really Great Place}
\newcommand\deptaddress{A Subdivision of this Place \\
  The first address line \\
  The second address line \\
  The third address line }
\newcommand\deptphone{123-456-7890 \\ Fax: 123-456-7890}
\newcommand\college{A Really Great Place}
\newcommand\eeo{Doing Very Interesting Things}
\newcommand\myname{Random Person \\
  Director of Randomness \\
  Email: \href{[email protected]}      {[email protected]}}
\newcommand\toName{Dear \toName}
\newcommand\toAddress{}
\newcommand\closing{Very Sincerely,}

% Header and Footer
\fancypagestyle{plain}{%
  \fancyhead{}%
  \renewcommand{\headrulewidth}{0pt}}

% Insert line between paragraphs and don't indent first line
\usepackage{parskip}
\setlength{\parskip}{0.8\baselineskip}
\pagestyle{empty}
\newsavebox{\startletter}
\makeatletter
\AtBeginDocument{%
  \changetext{0pt}{-2in}{1in}{1in}{0pt}%
  \sbox{\startletter}{%
    \parbox{\linewidth}{%
      \@date\bigskip\par
      \ifx\toName\@empty\else\toName\par\fi
      \ifx\toAddress\@empty\else\toAddress\bigskip\par\fi
      \toName\medskip\par}}
  \begin{tikzpicture}
    [
      remember picture, overlay, draw=XXXblue, text=XXXblue, font=\scriptsize, align=left
    ]
    \draw [line width=0.7pt] (current page.north west) +(1.18in,-1.0in) coordinate (c1) -- ($(-0.625in,-1.00in) + (current page.north east)$) coordinate (c2);
    \node (h1) [below=of c1, anchor=north west] {\includegraphics[width=2in]{\XXXlogo}};
    \node (h2) [right=10mm of h1, anchor=north west] {\deptphone};
    \node (h3) [right=10mm of h2.north east, font=\scriptsize\bfseries, anchor=north west] {\dept};
    \node (h4) [anchor=north east] at (h3.north -| c2) {\deptaddress};
    \node (c3) [above=.5in of c1 |- current page.south, anchor=south west] {\college};
    \node [font=\tiny, anchor=south east] at (c3.south -| c2) {\eeo};
    \node [below=of h1.south west, anchor=north west, text=black, font=\normalsize] {%
      \usebox{\startletter}};
  \end{tikzpicture}%
  \thispagestyle{empty}%
  \vspace*{4in}\par}
\makeatother


\AtEndDocument{%
  \bigskip\par
  \closing\medskip\par
  \includegraphics[width=1.5in]{\signature}\par
  \myname}
\usepackage{lipsum}

\def\toName{Some Really Important People}
\def\toAddress{Their Address \\ A place, Somewhere 55555}

\begin{document}

  \lipsum[1-2]
  \clearpage
  \changetext{0pt}{2in}{-1in}{-1in}{0pt}%
  \lipsum[3-6]

\end{document}

信纸上的信

相关内容