Title formatting the section makes the bibliography header disappear
I used a section style that I found here.
The problem is that the header of the bibliography becomes a box even though I've tried to make a separate style for unnumbered sections.
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
ul{#1}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Edit: This is the error message that shows up:
I came across hyphenatable material enclosed in group braces, which I
can't handle. Either drop the braces or make the material unbreakable
using an mbox (hbox). Note that a space also counts as possible
hyphenation point. See page 4 of the manual. I'm leaving a black
square so that you can see where I am right now.
sectioning formatting
add a comment |
I used a section style that I found here.
The problem is that the header of the bibliography becomes a box even though I've tried to make a separate style for unnumbered sections.
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
ul{#1}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Edit: This is the error message that shows up:
I came across hyphenatable material enclosed in group braces, which I
can't handle. Either drop the braces or make the material unbreakable
using an mbox (hbox). Note that a space also counts as possible
hyphenation point. See page 4 of the manual. I'm leaving a black
square so that you can see where I am right now.
sectioning formatting
1
This code is not compilable, and has no formatting for unnumbered sections.
– Bernard
Feb 22 at 14:18
Your MWE misses aend{thebibliography}
.
– Skillmon
Feb 22 at 15:16
@Skillmon Even if it's included, I still get a blue box instead of "References".
– Isomorphic Twin
Feb 22 at 15:18
1
@Bernardsection*{Foo}
does work.
– Skillmon
Feb 22 at 15:20
add a comment |
I used a section style that I found here.
The problem is that the header of the bibliography becomes a box even though I've tried to make a separate style for unnumbered sections.
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
ul{#1}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Edit: This is the error message that shows up:
I came across hyphenatable material enclosed in group braces, which I
can't handle. Either drop the braces or make the material unbreakable
using an mbox (hbox). Note that a space also counts as possible
hyphenation point. See page 4 of the manual. I'm leaving a black
square so that you can see where I am right now.
sectioning formatting
I used a section style that I found here.
The problem is that the header of the bibliography becomes a box even though I've tried to make a separate style for unnumbered sections.
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
ul{#1}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Edit: This is the error message that shows up:
I came across hyphenatable material enclosed in group braces, which I
can't handle. Either drop the braces or make the material unbreakable
using an mbox (hbox). Note that a space also counts as possible
hyphenation point. See page 4 of the manual. I'm leaving a black
square so that you can see where I am right now.
sectioning formatting
sectioning formatting
edited Feb 22 at 15:22
Isomorphic Twin
asked Feb 22 at 14:10
Isomorphic TwinIsomorphic Twin
1011
1011
1
This code is not compilable, and has no formatting for unnumbered sections.
– Bernard
Feb 22 at 14:18
Your MWE misses aend{thebibliography}
.
– Skillmon
Feb 22 at 15:16
@Skillmon Even if it's included, I still get a blue box instead of "References".
– Isomorphic Twin
Feb 22 at 15:18
1
@Bernardsection*{Foo}
does work.
– Skillmon
Feb 22 at 15:20
add a comment |
1
This code is not compilable, and has no formatting for unnumbered sections.
– Bernard
Feb 22 at 14:18
Your MWE misses aend{thebibliography}
.
– Skillmon
Feb 22 at 15:16
@Skillmon Even if it's included, I still get a blue box instead of "References".
– Isomorphic Twin
Feb 22 at 15:18
1
@Bernardsection*{Foo}
does work.
– Skillmon
Feb 22 at 15:20
1
1
This code is not compilable, and has no formatting for unnumbered sections.
– Bernard
Feb 22 at 14:18
This code is not compilable, and has no formatting for unnumbered sections.
– Bernard
Feb 22 at 14:18
Your MWE misses a
end{thebibliography}
.– Skillmon
Feb 22 at 15:16
Your MWE misses a
end{thebibliography}
.– Skillmon
Feb 22 at 15:16
@Skillmon Even if it's included, I still get a blue box instead of "References".
– Isomorphic Twin
Feb 22 at 15:18
@Skillmon Even if it's included, I still get a blue box instead of "References".
– Isomorphic Twin
Feb 22 at 15:18
1
1
@Bernard
section*{Foo}
does work.– Skillmon
Feb 22 at 15:20
@Bernard
section*{Foo}
does work.– Skillmon
Feb 22 at 15:20
add a comment |
1 Answer
1
active
oldest
votes
The problem seems the unexpanded name of the section (if I'm not mistaken). The following completely expands the given name with an edef
expansion (this might produce new issues, I'm not sure). It however works for your MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative
The following defines an alternative style, that formats unnumbered sections similar to the numbered ones (it uses report
and also defines chapter
to be matching, just remove that and you're good to go with article
). It also removes the unnecessary repetition of calling titleformat
for each sectioning level by defining a shorthand macro.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newcommand*TitleUnderline[1]
{%
begingroup
setul{dimexprdpstrutbox+fboxsep-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
endgroup
}
newcommand*SectionNumberBoxSep{TitleUnderline{ }}
newcommand*UnnumberedSectionNumberBox
{%
colorbox{titleblue}
{struthspace{dimexprhtstrutbox+dpstrutbox}}%
SectionNumberBoxSep
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
begingroup
color{white}%
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative 2
This version should look identical in print, but the display of the PDF depends on the viewer (xpdf can be trusted, though; this is because using ulem
the lines are built using small segments which might lead to aliasing issues on screens). It breaks automatic hyphenation, but remains line breakable. It uses the ulem
package instead of the soul
package. ulem
should be robuster, and therefore the edef
expansion is not needed with it.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage[normalem]{ulem}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newlengthTitleUnderlineSeg
setlengthTitleUnderlineSeg{.05pt}
newcommand*TitleUnderline[1]
{%
bgroup
markoverwith
{%
rule
[-dimexprdpstrutbox+fboxseprelax]
{TitleUnderlineSeg}
{.3ex}%
}%
ULon{#1}%
}
newcommand*SectionNumberBoxSep
{%
hspace{-TitleUnderlineSeg}%
TitleUnderline
{hspace{TitleUnderlineSeg}hspace{SectionNumberBoxPad}}%
}
newcommand*UnnumberedSectionNumberBox
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{struthspace{2SectionNumberBoxPad}}%
SectionNumberBoxSep
endgroup
}
newcommand*SectionNumberBox[1]
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{%
begingroup
color{white}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
endgroup
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
section
{Really long section name that is really long, so long it takes two rows}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
The lines do align vertically with the box of the section numbers (checked with xpdf
at 2000% magnification), the mismatch is due to Gimp's rasterization.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476173%2ftitle-formatting-the-section-makes-the-bibliography-header-disappear%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem seems the unexpanded name of the section (if I'm not mistaken). The following completely expands the given name with an edef
expansion (this might produce new issues, I'm not sure). It however works for your MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative
The following defines an alternative style, that formats unnumbered sections similar to the numbered ones (it uses report
and also defines chapter
to be matching, just remove that and you're good to go with article
). It also removes the unnecessary repetition of calling titleformat
for each sectioning level by defining a shorthand macro.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newcommand*TitleUnderline[1]
{%
begingroup
setul{dimexprdpstrutbox+fboxsep-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
endgroup
}
newcommand*SectionNumberBoxSep{TitleUnderline{ }}
newcommand*UnnumberedSectionNumberBox
{%
colorbox{titleblue}
{struthspace{dimexprhtstrutbox+dpstrutbox}}%
SectionNumberBoxSep
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
begingroup
color{white}%
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative 2
This version should look identical in print, but the display of the PDF depends on the viewer (xpdf can be trusted, though; this is because using ulem
the lines are built using small segments which might lead to aliasing issues on screens). It breaks automatic hyphenation, but remains line breakable. It uses the ulem
package instead of the soul
package. ulem
should be robuster, and therefore the edef
expansion is not needed with it.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage[normalem]{ulem}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newlengthTitleUnderlineSeg
setlengthTitleUnderlineSeg{.05pt}
newcommand*TitleUnderline[1]
{%
bgroup
markoverwith
{%
rule
[-dimexprdpstrutbox+fboxseprelax]
{TitleUnderlineSeg}
{.3ex}%
}%
ULon{#1}%
}
newcommand*SectionNumberBoxSep
{%
hspace{-TitleUnderlineSeg}%
TitleUnderline
{hspace{TitleUnderlineSeg}hspace{SectionNumberBoxPad}}%
}
newcommand*UnnumberedSectionNumberBox
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{struthspace{2SectionNumberBoxPad}}%
SectionNumberBoxSep
endgroup
}
newcommand*SectionNumberBox[1]
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{%
begingroup
color{white}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
endgroup
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
section
{Really long section name that is really long, so long it takes two rows}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
The lines do align vertically with the box of the section numbers (checked with xpdf
at 2000% magnification), the mismatch is due to Gimp's rasterization.
add a comment |
The problem seems the unexpanded name of the section (if I'm not mistaken). The following completely expands the given name with an edef
expansion (this might produce new issues, I'm not sure). It however works for your MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative
The following defines an alternative style, that formats unnumbered sections similar to the numbered ones (it uses report
and also defines chapter
to be matching, just remove that and you're good to go with article
). It also removes the unnecessary repetition of calling titleformat
for each sectioning level by defining a shorthand macro.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newcommand*TitleUnderline[1]
{%
begingroup
setul{dimexprdpstrutbox+fboxsep-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
endgroup
}
newcommand*SectionNumberBoxSep{TitleUnderline{ }}
newcommand*UnnumberedSectionNumberBox
{%
colorbox{titleblue}
{struthspace{dimexprhtstrutbox+dpstrutbox}}%
SectionNumberBoxSep
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
begingroup
color{white}%
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative 2
This version should look identical in print, but the display of the PDF depends on the viewer (xpdf can be trusted, though; this is because using ulem
the lines are built using small segments which might lead to aliasing issues on screens). It breaks automatic hyphenation, but remains line breakable. It uses the ulem
package instead of the soul
package. ulem
should be robuster, and therefore the edef
expansion is not needed with it.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage[normalem]{ulem}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newlengthTitleUnderlineSeg
setlengthTitleUnderlineSeg{.05pt}
newcommand*TitleUnderline[1]
{%
bgroup
markoverwith
{%
rule
[-dimexprdpstrutbox+fboxseprelax]
{TitleUnderlineSeg}
{.3ex}%
}%
ULon{#1}%
}
newcommand*SectionNumberBoxSep
{%
hspace{-TitleUnderlineSeg}%
TitleUnderline
{hspace{TitleUnderlineSeg}hspace{SectionNumberBoxPad}}%
}
newcommand*UnnumberedSectionNumberBox
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{struthspace{2SectionNumberBoxPad}}%
SectionNumberBoxSep
endgroup
}
newcommand*SectionNumberBox[1]
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{%
begingroup
color{white}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
endgroup
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
section
{Really long section name that is really long, so long it takes two rows}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
The lines do align vertically with the box of the section numbers (checked with xpdf
at 2000% magnification), the mismatch is due to Gimp's rasterization.
add a comment |
The problem seems the unexpanded name of the section (if I'm not mistaken). The following completely expands the given name with an edef
expansion (this might produce new issues, I'm not sure). It however works for your MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative
The following defines an alternative style, that formats unnumbered sections similar to the numbered ones (it uses report
and also defines chapter
to be matching, just remove that and you're good to go with article
). It also removes the unnecessary repetition of calling titleformat
for each sectioning level by defining a shorthand macro.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newcommand*TitleUnderline[1]
{%
begingroup
setul{dimexprdpstrutbox+fboxsep-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
endgroup
}
newcommand*SectionNumberBoxSep{TitleUnderline{ }}
newcommand*UnnumberedSectionNumberBox
{%
colorbox{titleblue}
{struthspace{dimexprhtstrutbox+dpstrutbox}}%
SectionNumberBoxSep
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
begingroup
color{white}%
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative 2
This version should look identical in print, but the display of the PDF depends on the viewer (xpdf can be trusted, though; this is because using ulem
the lines are built using small segments which might lead to aliasing issues on screens). It breaks automatic hyphenation, but remains line breakable. It uses the ulem
package instead of the soul
package. ulem
should be robuster, and therefore the edef
expansion is not needed with it.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage[normalem]{ulem}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newlengthTitleUnderlineSeg
setlengthTitleUnderlineSeg{.05pt}
newcommand*TitleUnderline[1]
{%
bgroup
markoverwith
{%
rule
[-dimexprdpstrutbox+fboxseprelax]
{TitleUnderlineSeg}
{.3ex}%
}%
ULon{#1}%
}
newcommand*SectionNumberBoxSep
{%
hspace{-TitleUnderlineSeg}%
TitleUnderline
{hspace{TitleUnderlineSeg}hspace{SectionNumberBoxPad}}%
}
newcommand*UnnumberedSectionNumberBox
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{struthspace{2SectionNumberBoxPad}}%
SectionNumberBoxSep
endgroup
}
newcommand*SectionNumberBox[1]
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{%
begingroup
color{white}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
endgroup
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
section
{Really long section name that is really long, so long it takes two rows}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
The lines do align vertically with the box of the section numbers (checked with xpdf
at 2000% magnification), the mismatch is due to Gimp's rasterization.
The problem seems the unexpanded name of the section (if I'm not mistaken). The following completely expands the given name with an edef
expansion (this might produce new issues, I'm not sure). It however works for your MWE:
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newboxTitleUnderlineTestBox
newcommand*TitleUnderline[1]
{%
bgroup
setboxTitleUnderlineTestBoxhbox{colorbox{titleblue}strut}%
setul{dimexprdpTitleUnderlineTestBox-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
egroup
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
makebox[2.5em][c]
{%
color{white}%
strut
csname the#1endcsname
}%
}%
TitleUnderline{ }%
}
titleformat{section}
{Largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{section}}
{0pt}
{TitleUnderline{#1}}
titleformat{subsection}
{largebfseriessffamilycolor{titleblue}}
{SectionNumberBox{subsection}}
{0pt}
{TitleUnderline{#1}}
begin{document}
maketitle
section{The First Section}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative
The following defines an alternative style, that formats unnumbered sections similar to the numbered ones (it uses report
and also defines chapter
to be matching, just remove that and you're good to go with article
). It also removes the unnecessary repetition of calling titleformat
for each sectioning level by defining a shorthand macro.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{soul}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newcommand*TitleUnderline[1]
{%
begingroup
setul{dimexprdpstrutbox+fboxsep-.3exrelax}{.3ex}%
edefmytmp{#1}%
expandafterulexpandafter{mytmp}%
endgroup
}
newcommand*SectionNumberBoxSep{TitleUnderline{ }}
newcommand*UnnumberedSectionNumberBox
{%
colorbox{titleblue}
{struthspace{dimexprhtstrutbox+dpstrutbox}}%
SectionNumberBoxSep
}
newcommand*SectionNumberBox[1]
{%
colorbox{titleblue}
{%
begingroup
color{white}%
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
Alternative 2
This version should look identical in print, but the display of the PDF depends on the viewer (xpdf can be trusted, though; this is because using ulem
the lines are built using small segments which might lead to aliasing issues on screens). It breaks automatic hyphenation, but remains line breakable. It uses the ulem
package instead of the soul
package. ulem
should be robuster, and therefore the edef
expansion is not needed with it.
documentclass{report}
usepackage[utf8]{inputenc}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage[normalem]{ulem}
definecolor{titleblue}{HTML}{4a7aa4}
title{Sections and Chapters}
author{Educ}
date{today}
newlengthSectionNumberBoxPad
newlengthTitleUnderlineSeg
setlengthTitleUnderlineSeg{.05pt}
newcommand*TitleUnderline[1]
{%
bgroup
markoverwith
{%
rule
[-dimexprdpstrutbox+fboxseprelax]
{TitleUnderlineSeg}
{.3ex}%
}%
ULon{#1}%
}
newcommand*SectionNumberBoxSep
{%
hspace{-TitleUnderlineSeg}%
TitleUnderline
{hspace{TitleUnderlineSeg}hspace{SectionNumberBoxPad}}%
}
newcommand*UnnumberedSectionNumberBox
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{struthspace{2SectionNumberBoxPad}}%
SectionNumberBoxSep
endgroup
}
newcommand*SectionNumberBox[1]
{%
begingroup
setlengthSectionNumberBoxPad{.5dimexprhtstrutbox+dpstrutbox}%
colorbox{titleblue}
{%
begingroup
color{white}%
hspace{SectionNumberBoxPad}%
strutcsname the#1endcsname
hspace{SectionNumberBoxPad}%
endgroup
}%
SectionNumberBoxSep
endgroup
}
makeatletter
newcommand*setuptitleformat[2]
{%
expandaftersetuptitleformat@csname #1endcsname{#1}{#2}%
}
newcommand*setuptitleformat@[3]
{%
titleformat{#1}
{#3bfseriessffamilycolor{titleblue}}
{SectionNumberBox{#2}}
{0pt}
{TitleUnderline{##1}}%
titleformat{name=#1,numberless}
{#3bfseriessffamilycolor{titleblue}}
{UnnumberedSectionNumberBox}
{0pt}
{TitleUnderline{##1}}%
}
makeatother
setuptitleformat{chapter}{LARGE}
setuptitleformat{section}{Large}
setuptitleformat{subsection}{large}
setuptitleformat{subsubsection}{}
setcounter{secnumdepth}{3}
setcounter{chapter}{10}
begin{document}
maketitle
chapter{The First Chapter}
section{The First Section}
subsection{The First Subsection}
subsubsection{The First Subsubsection}
Some text
section
{Really long section name that is really long, so long it takes two rows}
begin{thebibliography}{}
bibitem{}
end{thebibliography}
end{document}
The lines do align vertically with the box of the section numbers (checked with xpdf
at 2000% magnification), the mismatch is due to Gimp's rasterization.
edited Feb 22 at 21:22
answered Feb 22 at 15:23
SkillmonSkillmon
23k12044
23k12044
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476173%2ftitle-formatting-the-section-makes-the-bibliography-header-disappear%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This code is not compilable, and has no formatting for unnumbered sections.
– Bernard
Feb 22 at 14:18
Your MWE misses a
end{thebibliography}
.– Skillmon
Feb 22 at 15:16
@Skillmon Even if it's included, I still get a blue box instead of "References".
– Isomorphic Twin
Feb 22 at 15:18
1
@Bernard
section*{Foo}
does work.– Skillmon
Feb 22 at 15:20