GeneralChapter's title

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
n070161
Posts: 10
Joined: Fri Aug 27, 2010 11:16 pm

Chapter's title

Post by n070161 »

Hello,

I'm modifying the \chapter command in order to get (when a new chapter starts) something like this:
ChapterStyle.jpg
ChapterStyle.jpg (17.25 KiB) Viewed 3687 times
With some help from the frame.tss file of the titlesec package I got some almost perfect results, but I can't get the number (\thechapter) centered below the name (\chaptername)

Do someone have and idea of how can I do it?

Thank you!
Last edited by n070161 on Mon Aug 30, 2010 8:49 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Chapter's title

Post by frabjous »

Why don't you show us what code you have so far, so we can possibly suggest revisions?
n070161
Posts: 10
Joined: Fri Aug 27, 2010 11:16 pm

Chapter's title

Post by n070161 »

That's right, sorry.

*Edited*
There's the code that I'm using (from frame.tss):

Code: Select all

  \gdef\ttlh@frame#1#2#3#4#5#6#7#8{%
  \def\ttl@filleft##1{\hfill}%
  \def\ttl@filright##1{\hfill}%
  \gdef\ttl@makeline##1{%
    \ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}%
  \interlinepenalty\@M
  \ttl@changecentercr
  #1\ifhmode\ttl@hmode@error\fi
  \parindent\z@
  \leavevmode
  \@tempdima\fboxrule
  \addtolength\@tempdima{#3}%
  \setlength\leftskip{#6}%
  \setlength\rightskip{#7}%
  \lower\@tempdima\hbox{%
    \everypar{}%
    \setbox\z@\hbox{#2}%  
    \addtolength\hsize{-#6}%
    \addtolength\hsize{-#7}%
    \@tempdima\dp\z@ %  2002/3/22
    \advance\@tempdima.5\ht\z@
    \vbox{%
        \hbox to \hsize{%
          \leaders\hrule\@height\fboxrule\ttl@filleft{#3}%
          \ifttl@label\lower.5\ht\z@\box\z@\fi
          \leaders\hrule\@height\fboxrule\ttl@filright{#3}}%
        \vskip-\lineskip
        \ifttl@label\vskip-\@tempdima\fi
        \hbox{%
          \vrule\@width\fboxrule
          \kern-\fboxrule
          \vbox{%
             \ttl@calc\vspace{#3}%
             \leavevmode
	         \addtolength\leftskip {#3}\addtolength\leftskip{-#6}%
	         \addtolength\rightskip{#3}\addtolength\rightskip{-#7}%
	         \strut#4{#8}\kern\z@\strut\@@par
             \ttl@calc\vspace{#3}}%
          \kern-\fboxrule
          \vrule\@width\fboxrule}%
       \hrule\@height\fboxrule}}%
	   \@@par\nobreak#5\@@par}

The lane where \chaptername is printed is:
\setbox\z@\hbox{#2}%
and I would like to print \thechapter just below (and centered with "CHAPTER").

I hope I'm being clear, because my level of english and my level of LaTeX aren't as high as I want...
Last edited by n070161 on Mon Aug 30, 2010 6:31 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Chapter's title

Post by localghost »

Don't think so complicated. Just use the example on top of page 23 in the titlesec manual and adapt it to chapters.


Thorsten
n070161
Posts: 10
Joined: Fri Aug 27, 2010 11:16 pm

Re: Chapter's title

Post by n070161 »

First of all, sorry for the 'troubled' post (the external links and the code fragment).

I tried what you suggest, but I can't find the way of printing the number (\thechapter) below the name (\chaptername), so that's why I want to modify the underlying code, because the titlesec's default options aren't as flexible as I need

Thank you again.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Chapter's title

Post by frabjous »

I guess I also think it's easiest to stick with titlesec and make use of some tricks to get the flexibility you want. E.g., to set the chapter number centered underneath the word "Chapter", you could use the \underset command of amsmath or similar.

This is just a rough approximation; tweak as needed.

Code: Select all

\documentclass{book}
\usepackage{xcolor,titlesec,amsmath}
\setlength{\fboxrule}{7\fboxrule}   
\titleformat{\chapter}[frame]
{\normalfont\color{cyan}}
{\filright
    \enspace \textcolor{black}{$\underset{\textsf{\Huge\thechapter}}{\textsf{CHAPTER}}$} \enspace}
{8pt}
{\filleft\LARGE\sffamily\color{black}}

\begin{document}

\chapter{Chapter's title}

Hello world.

\end{document}
sample.png
sample.png (5.1 KiB) Viewed 3679 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Chapter's title

Post by localghost »

Based on the solution of frabjous, here's another idea that works with a \parbox. The output is attached.

Code: Select all

\documentclass{report}
\usepackage{titlesec}
\usepackage[x11names]{xcolor}

\newlength{\chpnamewidth}
\settowidth{\chpnamewidth}{\MakeUppercase{\chaptername}}

\setlength{\fboxrule}{7\fboxrule}   

\titleformat{\chapter}[frame]
{\normalfont\color{cyan}}
{\filright
    \enspace\textcolor{black}{\raisebox{1ex}{\parbox[t]{\chpnamewidth}{\centering\MakeUppercase{\chaptername}\\[-1ex] \Huge\thechapter}}}\enspace}
{8pt}
{\filleft\LARGE\sffamily\color{black}}


\begin{document}
  \chapter{Chapter's title}
    The quick brown fox jumps over the lazy dog.
\end{document}
Attachments
Framed chapter style as obtained with the provided code.
Framed chapter style as obtained with the provided code.
FramedChapter.png (4.55 KiB) Viewed 3678 times
n070161
Posts: 10
Joined: Fri Aug 27, 2010 11:16 pm

Re: Chapter's title

Post by n070161 »

Thank you very much :) both solutions worked for me

Really thank you
Post Reply