0

I want to do the table of contents of a book, but when I tried to use the command \chapter{} it doesn't work. I guess the problem is that I'm trying to put it in a \psframebox, however, I need it in that way. Or do you know a way I can include the chapter without the title appearing twice?

\documentclass[10pt,reqno,draft]{amsbook}
\usepackage[spanish]{babel}
\usepackage{latexsym}
\usepackage{amsmath,amsthm}
\usepackage{rawfonts}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pstricks}
%\usepackage{pst-all}
%\usepackage{pstcol}
\usepackage[utf8]{inputenc}
%\usepackage[latin1]{inputenc}

%\usepackage[pctex32]{graphics}
%\usepackage[pctex32]{graphicx}
\renewcommand{\theenumi}{\alph{enumi}}
\renewcommand{\theenumi}{\arabic{enumi}}
\newcommand{\lm}{\text{\rm lím\;}}
\newcommand{\sen}{\text{\;\rm sen\;}}
\newcommand{\tg}{\text{\;\rm tg\;}}
\setlength{\textwidth}{12.2cm}
\setlength{\textheight}{18cm}
\setlength{\headheight}{6mm}
\setlength{\footskip}{1.2cm}

\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage[spanish]{babel}
%\newpsobject{grilla}{psgrid}{subgriddiv=1,griddots=10}
\begin{document}
%\include{cap0}
\include{cap1}
\end{document}

In cap1.tex I put the following code

\pagestyle{fancy}
\fancyhead{}%

\fancyhead[CE]{\sc J}
\fancyhead[CO]{\sc Obra}

\renewcommand{\headrulewidth}{0.5pt}

\thispagestyle{empty}
\vspace*{1.5cm}

\chapter*{
\begin{flushright}
\psframebox[fillstyle=solid,fillcolor=black]
{{\huge\bf  \white ESCRITOS }}
\end{flushright}}

\setlength{\fboxrule}{1.5pt}
\setlength{\fboxsep}{10pt}


\newpage

3
  • Put \protect before \psframebox. Feb 21, 2022 at 22:33
  • @PietervanOostrum Thanks! It worked perfectly.
    – Merder
    Feb 21, 2022 at 22:41
  • @PietervanOostrum Sorry to bother you again, but It worked partially because the chapter name appears in the table of contents appears with the black box. I tried to put \protect before \psframebox, and \chapter{ESCRITOS}, however in the table of contents appears the letters in different sizes :(.
    – Merder
    Feb 21, 2022 at 22:52

1 Answer 1

1

Putting the formatting commands in the \chapter arguments is a bad idea, because they will also come in the table of contents and in the page header if you want the chapter title there. It is better to use a package like titlesec to do the job, because it separates the formatting from the text. Here is a solution based on titlesec. I also put some text in the chapter to make the picture nicer.

\documentclass[10pt,reqno,draft]{amsbook}
\usepackage[spanish]{babel}
\usepackage{latexsym}
\usepackage{amsmath,amsthm}
\usepackage{rawfonts}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pstricks}
%\usepackage{pst-all}
%\usepackage{pstcol}
\usepackage[utf8]{inputenc}
%\usepackage[latin1]{inputenc}

%\usepackage[pctex32]{graphics}
%\usepackage[pctex32]{graphicx}
\renewcommand{\theenumi}{\alph{enumi}}
\renewcommand{\theenumi}{\arabic{enumi}}
\newcommand{\lm}{\text{\rm lím\;}}
\newcommand{\sen}{\text{\;\rm sen\;}}
\newcommand{\tg}{\text{\;\rm tg\;}}
\setlength{\textwidth}{12.2cm}
\setlength{\textheight}{18cm}
\setlength{\headheight}{6mm}
\setlength{\footskip}{1.2cm}

\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage[spanish]{babel}
%\newpsobject{grilla}{psgrid}{subgriddiv=1,griddots=10}

\newcommand{\formatchapter}[1]{\raggedleft\psframebox[fillstyle=solid,fillcolor=black]{\huge\bf \white #1\strut}}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[block]
  {}
  {\formatchapter{\thechapter}}
  {0pt}
  {\formatchapter{#1}}

\usepackage{lipsum}

\begin{document}
\tableofcontents
%\include{cap0}
\include{cap1}
\end{document}

And cap1.tex

\pagestyle{fancy}
\fancyhead{}%

\fancyhead[CE]{\sc J}
\fancyhead[CO]{\sc Obra}

\renewcommand{\headrulewidth}{0.5pt}

\thispagestyle{empty}
\vspace*{1.5cm}

\chapter*{ESCRITOS}

\lipsum[1]

\setlength{\fboxrule}{1.5pt}
\setlength{\fboxsep}{10pt}

\newpage

In general I would advise to use the more modern \colorbox command instead of \psfancybox because it belongs to the standard LaTeX stuff. That can simply be done by replacing the \formatchapter command with

\newcommand{\formatchapter}[1]{\raggedleft\colorbox{black}{\huge\bf\textcolor{white}{#1}\strut}}

enter image description here enter image description here

You must log in to answer this question.

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