# chaptertitle name and chapter number in one line but diffrent edge of the page

This is what I want:

Introduction <---all the way on the right edge of the page---> Chapter 1

But, the catch is that I have a 5cm width margin note space in a two sided document. I am working with the book class if that helps...

• Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jul 28 '15 at 15:03
• Do you want the string "Chapter #" to be flushed to the right edge of the page? – Gonzalo Medina Jul 28 '15 at 15:56

Another solution with titlesec, which works also with multiline titles:

\documentclass[twoside]{book}

\usepackage[right=5cm, showframe]{geometry}
\usepackage[x11names]{xcolor}
\usepackage[explicit]{titlesec}

\titleformat{\chapter}{\Huge\bfseries}{\rlap{\hspace*{\dimexpr\textwidth + \marginparsep}\color{IndianRed3}\chaptername{} \thechapter}}{0pt}{#1}

\usepackage{lipsum}

\begin{document}
\mainmatter
\chapter{Introduction}

\lipsum[1-3]

\setcounter{chapter}{8}
\chapter{Another chapter. \\Yet another chapter.}

\lipsum[4-6]

\end{document}


• Have you tried \setcounter{chapter}{10}\chapter{Introduction}? – Ruben Jul 28 '15 at 17:24
• I only answered the O.P.'s requirements. In such a case he/she may modify the layout: change the values of marginparwidth, or decide the word ‘Chapter’ and chapter number will be in a tabular environment, in different rows. Inevitably there can be problem putting the label in the margin. It's up to the user to adapt the different parameters. – Bernard Jul 28 '15 at 17:39
• Where did the OP mention that the solution will be used with a document having less then ten chapters? – Ruben Jul 28 '15 at 17:53
• As I said, he can modify the parameters so as to fit marginparwidth: setting it to 5.5cm will do. Unless he uses Roman numbering. The code is pretty easy to adapt. Or make the label on two lines if he wants a Chapter MDCCCXVIII. I'm afraid there's no universal solution that works out of the box. – Bernard Jul 28 '15 at 18:03

I think you are most flexible if you redefine the \@makechapterhead by hand. (I'll add a remark with the reasons right before the complete code.)

Two parboxes, the first as wide as the \textwidth and the second as your right margin (5cm), side by side wrapped into a \hbox should do the job

\hbox{%
\parbox[t]{\the\textwidth}{\Huge\bfseries\raggedright#1}
\parbox[t]{5cm}{\huge\bfseries\raggedleft\@chapapp\space \thechapter}
}


As you see 'Chapter 1' gets pushed exactly to the edge. However, I would recommend to set the second \parbox to a little less then your right margin. I used 4.5cm in the final solution. Additionally I would add a little offset to the width of the first \parbox, so the final redefinition of \@makechapterhead is:

\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\dimen0=\dimexpr\textwidth-2em\relax
\hbox{%
\parbox[t]{\the\textwidth}{\Huge\bfseries\raggedright#1}
\parbox[t]{4.5cm}{\huge\bfseries\raggedleft\@chapapp\space \thechapter}
}
\par\nobreak
\fi
\fi
\interlinepenalty\@M
\vskip 40\p@
}
}


Now a few remarks:

• You need the e-TeX extension to compile the code. It should be in your distro by default. I just mention it for the sake of completeness.
• With this solution you can set the marginparwidth without interfering with the chapter number (see the last pic).
• You are able to deal with very long chapter headings (see the last pic).

Here is the complete code:

\documentclass[twoside]{book}
\usepackage{lipsum}
\usepackage[right=5cm,marginparwidth=2.5cm,marginparsep=2em]{geometry}
\usepackage{marginnote}

\makeatletter
\vspace*{50\p@}%
{\parindent \z@ \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\dimen0=\dimexpr\textwidth-2em\relax
\hbox{%
\parbox[t]{\the\dimen0}{\Huge\bfseries\raggedright#1}
\parbox[t]{4.5cm}{\huge\bfseries\raggedleft\@chapapp\space \thechapter}
}
\par\nobreak
\fi
\fi
\interlinepenalty\@M
\vskip 40\p@
}
}
\makeatother

\begin{document}
\chapter{Long long long long long long long Introduction}

\marginnote{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.}
\lipsum
\end{document}