TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to get n shorter strings out of a long one in Latex? Let's say I have something like \title{A very long title} and I want it to be broken into two pieces such that I can later use colorbox{red}{A very} and \color{blue}{long title}. The break point should be calculated through a distance provided by the user.

share|improve this question
Out of \title, yes, but you'll have to store the content first/before \maketitle since most document classes remove \@title - the placeholder macro. By distance, you mean characters? – Werner Oct 22 '12 at 14:11
@Werner by distance, I mean "if it is longer than 8cm break the title". Here the use of the \title{} command was just an example. What I have in mind is related to the \chapter{} command. – pluton Oct 22 '12 at 14:57
I don't think that, even if feasible in general, such an automatic procedure is good: breaking a title requires semantic considerations. For instance The story of\\my life would probably be better split as The story\\of my life. – egreg Oct 22 '12 at 21:04
ok, so the user could indicated where the title should be broken but the two (sub-)strings are still desired. – pluton Oct 23 '12 at 0:00
in which case a new command \chapter[optional]{substring1}{substring2} should be designed? – pluton Oct 23 '12 at 0:11
up vote 4 down vote accepted

I don't think you need anything special for the \chapter command:

\chapter[The real long title]
  {\textcolor{red}{The real}\\
   \textcolor{green}{long title}}

is all you need. You can abstract it with new commands:



\coloredchapter{\firstchapline{A really}\\\secondchapline{long title}}
\coloredchapter[Short title]{\firstchapline{A really}\\\secondchapline{long title}}
\coloredchapter*{\firstchapline{A really}\\\secondchapline{long title}}

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.