10

I would like to have

  • Title flush left
  • Author flush right
  • Date flush right

How can I do this on the same line or on a shared line? I was hope to achieve the following:

Title Author Date shared line

This is as far as I got using xelatex:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{titlesec, blindtext, color}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\section}[hang]{\Huge\bfseries}{Woche\hspace{.3cm}\thesection\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}

\usepackage{titling}
\pretitle{\begin{minipage}{0.4\textwidth}\begin{flushleft}\Huge}
\posttitle{\end{flushleft}\end{minipage}\hfill}
\predate{\hfill\begin{minipage}[t]{0.4\textwidth}\begin{flushright}\large}
\postdate{\end{flushright}\end{minipage}}

\title{Class Plan}

\begin{document}
\maketitle
\section{Less is More}
\blindtext
\end{document}

There is one catch. I need this to work in my .emacs file. I would like the MACRO #+Title and #+Author to work without extra code in my org-mode file

1 Answers1

11

The key is using boxes, in this case \parboxes (which allow for line breaks, as needed on the right) and putting them on the very left and right with \hfill in between.

Besides that, I wouldn't try to fix up \maketitle if I don't absolutely have to, but instead just create the title from scratch. To access the values of \author and \title, we can use the titling package.

The section titles can be done with a quick fix, too.

Here are a basic version and one that's closer to your image:

\documentclass{article}

\usepackage{titling}
    \author{Author}
    \title{Class Plan}
    \date{\today}

\usepackage{xcolor}
    \definecolor{titlebg}{RGB}{186,48,39}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{blindtext}

\renewcommand{\thesection}{Week \arabic{section}\hspace{1em}|}

\begin{document}

Basic version: \bigskip

\noindent\parbox{\linewidth}{%
\parbox{.4\linewidth}{\fontsize{24}{28}\selectfont\thetitle}\hfill%
\parbox{.4\linewidth}{\fontsize{12}{14}\selectfont\raggedleft\today\\\theauthor%
}}

\bigskip Fancier version: \bigskip

\noindent\colorbox{titlebg}{%
\parbox{\dimexpr\linewidth-2\fboxsep}{\color{white}%
\parbox{.4\linewidth}{\fontsize{24}{28}\selectfont\sffamily\bfseries\thetitle}\hfill%
\parbox{.4\linewidth}{\fontsize{12}{14}\selectfont\raggedleft\thedate\\\theauthor%
}}}

\section{Less is More}
\blindtext
\end{document}

output


Edit:

As egreg said, just redefine \maketitle as a whole and put this in a .sty file:

\renewcommand*{\maketitle}{\noindent\colorbox{titlebg}{%
\parbox{\dimexpr\linewidth-2\fboxsep}{\color{white}%
\parbox{.4\linewidth}{\fontsize{24}{28}\selectfont\sffamily\bfseries\thetitle}\hfill%
\parbox{.4\linewidth}{\fontsize{12}{14}\selectfont\raggedleft\today\\\theauthor%
}}}}

I'm not familiar with emacs at all, so I can't help you with that, if the package solution is not what you're looking for. In that case, I would probably recommend asking a separate question about what you're trying to do because it seems to be independent from the styling of the title (obeying our one-issue-per-question guideline).

Some resources on writing a package (= .sty file):

doncherry
  • 54,637
  • I did mark your answer as correct, but perhaps it was premature. It did indeed answer my question, however, I did not make my question clear enough. My ultimate goal is to include all of this in my .emacs file for a xelatex export. I was hoping to keep my solution above the \begin{document}, but your solution involves code below this point. Do you know how I could solve this? That is why I wanted to edit the \maketitle and I think in this case, I have to! – Jonathan Komar Nov 05 '12 at 18:47
  • 1
    @macmadness86 The right place for that kind of code is not the .emacs file, but rather a personal .sty file. Just put the relevant code in a redefinition of \maketitle, inside macmadness.sty and do \usepackage{macmadness} after storing the package in one of the canonical places (~/Library/texmf/tex/latex/macmadness on Mac OS X with MacTeX). – egreg Nov 05 '12 at 19:05
  • @macmadness86: I agree with egreg, and see my edit. – doncherry Nov 05 '12 at 19:16
  • @egreg I don't want to be one to argue with you, since you are like a tex genius answering every question on this site :) and you have helped me numerous times, but I would like to point out this site: http://orgmode.org/worg/org-tutorials/org-latex-export.html which suggests putting these things in the .emacs file. Not sure if that is what you mean, but I have many templates in my .emacs which are selected with #+LaTeX_CLASS . Anyway, I would like to make my solution as portable as possible between computers, which is why I don't really want a .sty file. I suppose I could do it – Jonathan Komar Nov 05 '12 at 19:24
  • @doncherry Thanks for posting how to do with egreg suggested, because I did not know how to do that! I will try it out. I assume with a personal .sty file I can still use the article class? I would rather not have my own style in order to make my workflow more portable. – Jonathan Komar Nov 05 '12 at 19:24
  • @macmadness86 .sty files are the epitome of LaTeX's portability! .emacs files presumably only work with emacs, .sty files work editor-independently! As a matter of fact, in the code you provided, you're loading fontenc.sty, titlesec.sty, blindtext.sty, color.sty & titling.sty -- and you can be sure that these packages load even more .sty files in the background. And yes, you can keep using article. A .sty file (= a package) is essentially nothing but normal LaTeX code put in an external file. \input{} is similar, but usually used for document content. – doncherry Nov 05 '12 at 19:27
  • 1
    @doncherry i meant between tex live installs. so that i can compile a file on any computer without needed to install a style file first. You make it sound fantastic though. You should go into sty file marketing :) – Jonathan Komar Nov 05 '12 at 19:31
  • 1
    @macmadness86 "Installing" a style file is as easy as putting it in the directory of the mydocument.tex file that you're compiling. If you want to make it as available on a system as any other .sty file, you'll have to put it in your texmf tree, as egreg indicated. – doncherry Nov 05 '12 at 19:34
  • @doncherry Thank you for that! I did not know you could just put it in the same directory as the tex file. I thought you had to put it in the texmf tree. I wanted to avoid that step, but I think I can live this solution! Both of you have been very helpful. Thanks guys! – Jonathan Komar Nov 05 '12 at 19:39