4

I'm looking to do homework in LaTeX. I'd like the format to be as follows: A simple enumerated list of the answers (with simple numbers on the same line, not section markers) with a heading on the top right corner of the first page only. I'd also like smaller margins and 12pt font. The list, the margins, and the font I've taken care of with

\documentclass[a4paper, 12pt]{article}
\usepackage{enumitem}
\usepackage{fullpage}
\begin{document}
\begin{enumerate}

 \item[1.] Here is some text. $$f(x+h) = f(x) + f'(x)h + o(h).$$

\end{enumerate}
\end{document}

I'm now trying to figure out how to get a heading in the upper right hand corner of the first page. I searched through old answers on the site with no success.

Eric Auld
  • 1,223

1 Answers1

7

There is technically no need to place what you're after in the page header. I would just set it as part of the text block - the first thing on the first page, flush right:

enter image description here

\documentclass[12pt]{article}
\usepackage[paper=a4paper,margin=1in]{geometry}
\begin{document}
\null\hfill\begin{tabular}[t]{l@{}}
  \textbf{My name} \\
  \textit{My University}
\end{tabular}

\begin{enumerate}
  \item
  Here is some text. $f(x+h) = f(x) + f'(x)h + \mathcal{O}(h)$.
\end{enumerate}
\end{document}

I've used geometry to set the page boundary/size. Adjust to your liking. The idea behind a tabular is only to emphasize that you can make a construction of what you want to place as your "header" that contain multiple lines. However, if you just want a single entry, there may be no need for using tabular.

Werner
  • 603,163
  • I like this idea a lot! When you write \null\hfill\begin{tabular}{t]{l@{}}, I'm assuming that's all standard tabular stuff I can find at http://en.wikibooks.org/wiki/LaTeX/Tables#The_tabular_environment? Thanks – Eric Auld Mar 26 '14 at 18:37
  • 1
    @EricAuld: \null sets an anchor in the text (which is just an empty, zero-width box. \hfill then inserts a horizontal fill to make whatever follows flush with the right margin. What follows is just a block created using tabular, for which you can find information in the link you provided. – Werner Mar 26 '14 at 18:46
  • I am in a similar predicament as the OP, but I would like my name to show up each page of the homework. Is there any way to get that table into a header so it is replicated on all pages? – kingledion Mar 20 '17 at 23:47
  • 1
    @kingledion: Sure. Add \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \renewcommand{\headrulewidth}{0pt} \fancyhead[R]{<tab>} \setlength{\headheight}{2\baselineskip} and fill in whatever for <tab>. – Werner Mar 20 '17 at 23:49
  • @Werner Wow, thanks for the quick response. I had to up the \headheight to 4 to keep the header on the page, but it worked great. – kingledion Mar 20 '17 at 23:53
  • @kingledion: Yes. If it's too short, you'll see a warning in your .log. Set it to at least that. – Werner Mar 20 '17 at 23:54