3

I want center the title "Preface" and "Abstract" only. I do not want to centralize all the chapters. I can not and I should not delete any bookstore, I need all the libraries.

\documentclass{book}
\usepackage[left=3cm, right=2cm, top=2cm, bottom=2cm]{geometry}
\usepackage{lipsum}
\usepackage{lscape}
\usepackage[utf8]{inputenc}

\usepackage[spanish,es-tabla]{babel}

\usepackage[table]{xcolor} 

\usepackage{sectsty}
\sectionfont{\fontsize{12pt}{14.4pt}\selectfont\sffamily\bfseries}
\subsectionfont{\fontsize{11.5pt}{13.8pt}\selectfont\sffamily\bfseries}
\subsubsectionfont{\normalsize\sffamily\bfseries}



\begin{document}

\chapter*{\centering Preface}


Some text
\chapter*{\centering Abstract}


\chapter{Introduction}
\chapter{Body}
\chapter{Conclusion}

\end{document}
  • Should all chapter titles be centred, or only unnumbered chapters? – Bernard Nov 21 '18 at 23:56
  • @Bernard only two, Preface and Abstract – x-rw Nov 21 '18 at 23:57
4

Set the title inside a \makebox[\linewidth]; this naturally centres it. It would not have any impact on headers or the ToC since these elements don't end up there.

enter image description here

\documentclass{book}

\usepackage{lipsum}

\begin{document}

\chapter*{\makebox[\linewidth]{Preface}}
\lipsum[1]

\chapter*{\makebox[\linewidth]{Abstract}}
\lipsum[2]

\chapter{Introduction}
\chapter{Body}
\chapter{Conclusion}

\end{document}
0

Using the tools from sectsty:

\documentclass{book}
\usepackage[left=3cm, right=2cm, vmargin=2cm]{geometry}
\usepackage{lipsum}
\usepackage{lscape}
\usepackage[utf8]{inputenc}

\usepackage[spanish,es-tabla]{babel}

\usepackage[table]{xcolor}

\usepackage{sectsty}
\sectionfont{\fontsize{12pt}{14.4pt}\selectfont\sffamily\bfseries}
\subsectionfont{\fontsize{11.5pt}{13.8pt}\selectfont\sffamily\bfseries}
\subsubsectionfont{\normalsize\sffamily\bfseries}

\begin{document}

\chapterfont{\huge\bfseries\centering}
\chapter*{\centering Preface}

Some text
\chapter*{\centering Abstract}

\chapterfont{\huge\bfseries\raggedright}
\chapter{Introduction}
\chapter{Body}
\chapter{Conclusion}

\end{document} 

enter image description here

enter image description here

0

Fast solution

You could set a manual space

\chapter*{\hspace{.4\textwidth}Preface}

which puts the title almost in the middle of the page

Reasoned solution

Otherwise you could think of measuring the length of your title and make the thing more precise with the package calc

%PREAMBLE
\usepackage{calc}

\newlength\mylen
\newcommand\chaplen[1]{
    \setlength\mylen{(\textwidth-\widthof{\Huge\bfseries #1})/2}
}

%... BEGIN DOCUMENT

\chaplen{Preface}
\chapter*{\hspace*{\mylen}Preface}

\chaplen{OTHER}
\chapter*{\hspace*{\mylen}OTHER}

enter image description here

FUll code:

\documentclass{book}
\usepackage[left=3cm, right=2cm, top=2cm, bottom=2cm]{geometry}
\usepackage{lipsum}
\usepackage{lscape}
\usepackage[utf8]{inputenc}

\usepackage[spanish,es-tabla]{babel}

\usepackage[table]{xcolor} 

\usepackage{sectsty}
\sectionfont{\fontsize{12pt}{14.4pt}\selectfont\sffamily\bfseries}
\subsectionfont{\fontsize{11.5pt}{13.8pt}\selectfont\sffamily\bfseries}
\subsubsectionfont{\normalsize\sffamily\bfseries}

\usepackage{calc}

\newlength\mylen
\newcommand\chaplen[1]{
    \setlength\mylen{(\textwidth-\widthof{\Huge\bfseries #1})/2}
    }

\begin{document}

\chaplen{Preface}
\chapter*{\hspace*{\mylen}Preface}


Some text
\chaplen{Abstract}
\chapter*{\hspace*{\mylen}Abstract}


\chapter{Introduction}
\chapter{Body}
\chapter{Conclusion}

\end{document}
  • 1
    Does not centralize well, another option? – x-rw Nov 21 '18 at 23:53
  • Why you multiplied by 2? – Sigur Nov 21 '18 at 23:56
  • 1
    I think it is still wrong. If it would work, it should be (x-y)/2. – Sigur Nov 21 '18 at 23:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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