1

I retrieved the method \renewcommand MakeTitle to set the color of the title.

\makeatletter
\renewcommand{\title}[1]{\renewcommand{\@title}{\color{\@titlecolor}#1}}
\newcommand{\@titlecolor}{red}
\newcommand{\titlecolor}[1]{\renewcommand{\@titlecolor}{#1}}
\makeatother

This was very successful and worked for me. I used a similar command to modify the author, but only part of the author changed the color.

\documentclass[10pt]{article}
\usepackage{color}
\makeatletter

\renewcommand{\author}[1]{\renewcommand{\@author}{\color{\@authorcolor}#1}}
\newcommand{\@authorcolor}{red}
\newcommand{\authorcolor}[1]{\renewcommand{\@authorcolor}{#1}}
\makeatother
\title{My Title}
\author{Author One$^1$ \\ Author Two$^2$ 
  \\
    \normalsize{$^1$Organization 1}\\
    \normalsize{$^2$Organization 2}\\
    \\
    \normalsize{Emails: [email protected], [email protected]}\thanks{Thanks} }


\begin{document}
\maketitle
\end{document}

output:

enter image description here

Could you please design a better scheme to change the color of all contents in author (including \thanks, etc.)? By the way, SINCE I have a lot of documents to work with, I'd like to do that through renewcommand.

2
  • Can use Lua to process the code (add color-changing command every `\`) and print back.
    – user202729
    Dec 31, 2021 at 4:21
  • Formatting instructions belong to \maketitle rather than \author or \title
    – egreg
    Dec 31, 2021 at 9:07

1 Answer 1

1

You essentially have to understand the structure of the title construction. The \title (or \@title) typically contains only a single element, so colouring it is fairly easy/straight forward. However, since the \author (or \@author) could include multiple members/elements, it's set by default inside a tabular; this allows you to use \\ to separate authors. This does, however, provide limited scope. In fact, each cell forms a group, which explains why your change in colour only applies to the first cell.

Knowing the \@author is structured like a tabular, the following updates your redefinition of \author to know set the \@author within a (nested) tabular, allowing the colour to apply across the entire (nested) author list.

enter image description here

\documentclass{article}

\usepackage{xcolor}

\makeatletter
\renewcommand{\author}[1]{\renewcommand{\@author}{%
  \color{\@authorcolor}
  \begin{tabular}{@{}c@{}}
    #1
  \end{tabular}}}
\newcommand{\@authorcolor}{red}
\newcommand{\authorcolor}[1]{\renewcommand{\@authorcolor}{#1}}
\makeatother

\title{A Title}
\author{%
  Author One\textsuperscript{1} \\
  Author Two\textsuperscript{2} \\
  \textsuperscript{1}Organization 1 \\
  \textsuperscript{2}Organization 2 \\
  \\
  Emails: [email protected], [email protected]\thanks{Thanks}
}

\begin{document}

\maketitle

\end{document}
4
  • Thank you for your answers, your answers work well on my task! In addition, I would like to ask you how to renewcommand the color of /thanks.
    – happy
    Dec 31, 2021 at 5:57
  • Hello, I found a problem. It seems that I cannot handle commands of this type \author[1]{author name}.
    – happy
    Dec 31, 2021 at 7:39
  • @happy: And what would \author[1]{author name} represent? What does the optional argument do?
    – Werner
    Dec 31, 2021 at 12:16
  • Yes, I found that when there are parameters, it will not change the color or produce wrong results.
    – happy
    Jan 1, 2022 at 5:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .