本科期间,我勉强用这个模板做作业,忽略或绕过它的小问题。我想最终弄清楚如何解决我遇到的一些问题,并希望在此过程中提高/刷新我的 LaTeX 技能。除了这些问题之外,我对它非常满意。
第一个问题是,在页脚中,“下页继续”行往往会与页脚中的中心线重叠:“作业班(作业班讲师)”,这通常可能相对较长。我认为,如果插入后续文本,最好将它们作为单独的行。
第二个问题是,只有答案长度少于一页时,答案所在的 fbox(如 所示\newcommand{\problemAnswer}
)才会起作用。我认为最简单的方法可能是取消 fbox,反正我不喜欢它,然后想出其他区分问题和答案的方法。您有什么好的办法可以做到这一点吗?
\documentclass{article}
% Change "article" to "report" to get rid of page number on title page
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{setspace}
\usepackage{Tabbing}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{extramarks}
\usepackage{chngpage}
\usepackage{soul,color}
\usepackage{graphicx,float,wrapfig}
%units package: Pick one
%\usepackage{gensymb}
\usepackage{siunitx}
% In case you need to adjust margins:
\topmargin=-0.45in %
\evensidemargin=0in %
\oddsidemargin=0in %
\textwidth=6.5in %
\textheight=9.0in %
\headsep=0.25in %
% Homework Specific Information
\newcommand{\hmwkTitle}{Homework Title}
\newcommand{\hmwkDueDate}{Homework Due Date}
\newcommand{\hmwkClass}{Homework Class}
\newcommand{\hmwkClassInstructor}{Homework Class Instructor}
\newcommand{\hmwkAuthorName}{Author Name}
% Setup the header and footer
\pagestyle{fancy} %
\lhead{\hmwkAuthorName} %
\rhead{\hmwkTitle} %
\lfoot{\lastxmark} %
\cfoot{\hmwkClass\ (\hmwkClassInstructor)} %
\rfoot{Page\ \thepage\ of\ \pageref{LastPage}} %
\renewcommand\headrulewidth{0.4pt} %
\renewcommand\footrulewidth{0.4pt} %
% This is used to trace down (pin point) problems
% in latexing a document:
%\tracingall
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some tools
\newcommand{\enterProblemHeader}[1]{\nobreak\extramarks{#1}{#1 continued on next page\ldots}\nobreak%
\nobreak\extramarks{#1 (Continued)}{#1 continued on next page\ldots}\nobreak}%
\newcommand{\exitProblemHeader}[1]{\nobreak\extramarks{#1 (Continued)}{#1 continued on next page\ldots}\nobreak%
\nobreak\extramarks{#1}{}\nobreak}%
\newlength{\labelLength}
\newcommand{\labelAnswer}[2]
{\settowidth{\labelLength}{#1}%
\addtolength{\labelLength}{0.25in}%
\changetext{}{-\labelLength}{}{}{}%
\noindent\fbox{\begin{minipage}[c]{\columnwidth}#2\end{minipage}}%
\marginpar{\fbox{#1}}%
% We put the blank space above in order to make sure this
% \marginpar gets correctly placed.
\changetext{}{+\labelLength}{}{}{}}%
\setcounter{secnumdepth}{0}
\newcommand{\homeworkProblemName}{}%
\newcounter{homeworkProblemCounter}%
\newenvironment{homeworkProblem}[1][Problem \arabic{homeworkProblemCounter}]%
{\stepcounter{homeworkProblemCounter}%
\renewcommand{\homeworkProblemName}{#1}%
\section{\homeworkProblemName}%
\enterProblemHeader{\homeworkProblemName}}%
{\exitProblemHeader{\homeworkProblemName}}%
\newcommand{\problemAnswer}[1]
{\noindent\fbox{\begin{minipage}[c]{\columnwidth}#1\end{minipage}}}%
\newcommand{\problemLAnswer}[1]
{\labelAnswer{\homeworkProblemName}{#1}}
\newcommand{\homeworkSectionName}{}%
\newlength{\homeworkSectionLabelLength}{}%
\newenvironment{homeworkSection}[1]%
{% We put this space here to make sure we're not connected to the above.
% Otherwise the changetext can do funny things to the other margin
\renewcommand{\homeworkSectionName}{#1}%
\settowidth{\homeworkSectionLabelLength}{\homeworkSectionName}%
\addtolength{\homeworkSectionLabelLength}{0.25in}%
\changetext{}{-\homeworkSectionLabelLength}{}{}{}%
\subsection{\homeworkSectionName}%
\enterProblemHeader{\homeworkProblemName\ [\homeworkSectionName]}}%
{\enterProblemHeader{\homeworkProblemName}%
% We put the blank space above in order to make sure this margin
% change doesn't happen too soon (otherwise \sectionAnswer's can
% get ugly about their \marginpar placement.
\changetext{}{+\homeworkSectionLabelLength}{}{}{}}%
\newcommand{\e}[1]{\ensuremath{\times 10^{#1}}}
\newcommand{\sectionAnswer}[1]
{% We put this space here to make sure we're disconnected from the previous
% passage
\noindent\fbox{\begin{minipage}[c]{\columnwidth}#1\end{minipage}}%
\enterProblemHeader{\homeworkProblemName}\exitProblemHeader{\homeworkProblemName}%
\marginpar{\fbox{\homeworkSectionName}}%
% We put the blank space above in order to make sure this
% \marginpar gets correctly placed.
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make title
\title{\vspace{2in}\textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\\normalsize\vspace{0.1in}\small{Due\ on\ \hmwkDueDate}\\\vspace{0.1in}\large{\textit{\hmwkClassInstructor}}\vspace{3in}}
\date{}
\author{\textbf{\hmwkAuthorName}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{spacing}{1.1}
\maketitle
\newpage
% Uncomment the \tableofcontents and \newpage lines to get a Contents page
% Uncomment the \setcounter line as well if you do NOT want subsections
% listed in Contents
%\setcounter{tocdepth}{1}
%\tableofcontents
%\newpage
% When problems are long, it may be desirable to put a \newpage or a
% \clearpage before each homeworkProblem environment
\clearpage
\begin{homeworkProblem}
Question.
\problemAnswer
{
Answer.
}
\end{homeworkProblem}
\begin{homeworkProblem}
Question.
\begin{homeworkSection}{Section 1 Title}
Section 1.
\sectionAnswer
{
Answer.
}
\end{homeworkSection}
\begin{homeworkSection}{Section 2 Title}
Section 2.
\sectionAnswer
{
Answer.
}
\end{homeworkSection}
\end{homeworkProblem}
\end{spacing}
\end{document}
答案1
您可以使用以下方式让框架继续在下一页上框架\problemAnswer
包并改变的定义
\newcommand{\problemAnswer}[1]{\begin{framed}#1\end{framed}}
对于连续消息,您需要缩短页脚中出现的部分内容,或者将连续消息放在不同的行上。“较短”版本的一种可能性是使用:
\newcommand{\enterProblemHeader}[1]{%
\nobreak\extramarks{#1}{#1 continues\ldots}\nobreak%
\nobreak\extramarks{#1 (Continued)}{#1 continues\ldots}\nobreak}%
\newcommand{\exitProblemHeader}[1]{%
\nobreak\extramarks{#1 (Continued)}{#1 continues\ldots}\nobreak%
\nobreak\extramarks{#1}{}\nobreak}%
对于您的 MWE,这将产生:
偶然间我发现了一个可以将连续消息移到下一行的 hack。我还没有尝试找出导致这种情况的原因,但如果你\color{black}
在适当的位置添加,那么你的页脚消息将如下所示:
这是通过使用以下方法实现的:
\newcommand{\enterProblemHeader}[1]{%
\nobreak\extramarks{#1}{#1 continued on next page\ldots}\nobreak%
\nobreak\extramarks{#1 (Continued)}{\color{black}#1 continued on next page\ldots}\nobreak}%
\newcommand{\exitProblemHeader}[1]{%
\nobreak\extramarks{#1 (Continued)}{\color{black}#1 continued on next page\ldots}\nobreak%
\nobreak\extramarks{#1}{}\nobreak}%
话虽如此,如果我写这样的东西,我可能会使用彩色盒子包装既可用于家庭作业框,也可用于页脚。有关您可以通过这种方式在页脚中执行的操作的示例,请参阅 如何在页脚中添加表格。