如何在自定义标题中居中标题?

如何在自定义标题中居中标题?

现在我的标题看起来像这样 在此处输入图片描述

如您所见,居中位置有点不对。我真正希望的是,元素 1 和元素 3 不居中,而“CS 2800”和“Homework 1”居中。

如果有人能告诉我怎么做,我将不胜感激!我使用的乳胶代码如下:

% Use this template to write your solutions

\documentclass[12pt]{article}
\usepackage[intlimits, sumlimits]{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{enumerate}
\usepackage{microtype}

% Set the margins
%
\setlength{\textheight}{8.5in}
\setlength{\headheight}{.25in}
\setlength{\headsep}{.25in}
\setlength{\topmargin}{0in}
\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}

% Macros
\newcommand{\myN}{\hbox{N\hspace*{-.9em}I\hspace*{.4em}}}
\newcommand{\myZ}{\hbox{Z}^+}
\newcommand{\myR}{\hbox{R}}

\newcommand{\myfunction}[3]
{${#1} : {#2} \rightarrow {#3}$ }

\newcommand{\myzrfunction}[1]
{\myfunction{#1}{{\myZ}}{{\myR}}}


% Formating Macros

\newcommand{\myheader}[6]
{\vspace*{-0.5in}
\noindent
{#1} \hfill {#2} \hfill {#3}

\noindent
{#4} \hfill {#5} \hfill {#6}

\noindent
\rule[8pt]{\textwidth}{1pt}

\vspace{1ex} 
}  % end \myheader 

\newcommand{\myalgsheader}[0]
{\myheader
{ {}}
{ {\Large CS 2800}}
{ {}}
{ {Monica}}
{ {Homework 1}}
{ {February 8, 2015}}
}

%%%%%% Begin document with header and title %%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\myalgsheader

\pagestyle{plain}

% \myhwtitle{x}{y}{clem, Lee, Clement}
% Example : \myhwtitle{1}{4}{Your name here}

\bigskip

% begin Solution 
Your problem solution.
% end Solution 

\end{document}

答案1

我将加载该fancyhdr包并将以下代码放在序言中:

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Monica}
\chead{\begin{tabular}[b]{c}
       \Large CS2800 \\ Homework 1
       \end{tabular}}
\rhead{February 8, 2015}

文档主体部分将以如下形式开始:

\begin{document}
\pagestyle{plain}
\thispagestyle{fancy}
...

在此处输入图片描述

答案2

有点不同@Mico 解决方案稍后再说。

\documentclass{report}
\usepackage{lipsum}
\usepackage[showframe,head=2.5em]{geometry}
\usepackage{fancyhdr}
\lhead{%
\begin{tabular}{@{}l}
Element 1\\Monica
\end{tabular}%
}
\rhead{%
\begin{tabular}{r@{}}
Element 3\\\today
\end{tabular}%
}
\chead{%
\begin{tabular}{c}
{\large CS 2800}\\Homework 1
\end{tabular}%
}

\begin{document}
\pagestyle{fancy}
\lipsum[1]
\end{document}

在此处输入图片描述

相关内容