How to add frame around section using titlesec?

Multi tool use
I want exact this section style but I am unable to add frame around it. Could you please help me? Here is my code snippet :
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage{titlesec, blindtext, color}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[hang]{Largebfseries}{thesectionhsptextcolor{seccolor}{|}hsp}{0pt}{Largebfseries}
begin{document}
section{Section Name}
blindtext
end{document}
sectioning pdftex titlesec framed
add a comment |
I want exact this section style but I am unable to add frame around it. Could you please help me? Here is my code snippet :
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage{titlesec, blindtext, color}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[hang]{Largebfseries}{thesectionhsptextcolor{seccolor}{|}hsp}{0pt}{Largebfseries}
begin{document}
section{Section Name}
blindtext
end{document}
sectioning pdftex titlesec framed
add a comment |
I want exact this section style but I am unable to add frame around it. Could you please help me? Here is my code snippet :
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage{titlesec, blindtext, color}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[hang]{Largebfseries}{thesectionhsptextcolor{seccolor}{|}hsp}{0pt}{Largebfseries}
begin{document}
section{Section Name}
blindtext
end{document}
sectioning pdftex titlesec framed
I want exact this section style but I am unable to add frame around it. Could you please help me? Here is my code snippet :
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage{titlesec, blindtext, color}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[hang]{Largebfseries}{thesectionhsptextcolor{seccolor}{|}hsp}{0pt}{Largebfseries}
begin{document}
section{Section Name}
blindtext
end{document}
sectioning pdftex titlesec framed
sectioning pdftex titlesec framed
edited 5 hours ago
Ravi
asked 6 hours ago
RaviRavi
1457
1457
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can have it with TikZ and explicit
option of titlesec
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
With very long section titles (with help from this question):
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
If you want to have "|" instead of "—", as in the attached figure, you can use textbar
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{textbar}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
However, a vertical line like this is much better I think.
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
usetikzlibrary{positioning}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikz[font=Largebfseries]{node[draw,minimum height=.75cm] (x) {thesection};node[minimum height=.75cm,below right=0pt and 0pt of x.north west,draw,max width=textwidth-.6666em-.4pt]{hspace{.3333em}phantom{thesection}hspace{.3333em}#1};}}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
Thanks a million!
– Ravi
5 hours ago
1
Nice answer. Maybe the relative positioning of TikZ nodes should use anchors on the baseline, andstrut
to ensure the top (resp. bottom) lines from section number and title nodes are at the same height, rather than north west and a hardcoded minimum height...
– frougon
3 hours ago
1
@frougon Thanks for the suggestion. Actually I use this way because I am not so familiar withanchor
. Maybe I will consider it when I have much free time.
– JouleV
3 hours ago
@JouleV I haven't expected so much. Thanks again.
– Ravi
1 hour ago
1
@Ravi You are welcome.
– JouleV
1 hour ago
add a comment |
Solution based on fbox
, using textbar
for the vertical bar, and with a variant for unnumbered sections (section*
):
documentclass[10pt,a4paper,twoside]{report}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{blindtext}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
newcommand*{sectionFont}{%
Largebfseries
}
% For section
titleformat{section}[block]{sectionFont}{}{0pt}{%
fbox{thesection hsp textcolor{seccolor}{textbar}hsp #1}}
% For section*
titleformat{name=section, numberless}[block]{sectionFont}{}{0pt}{%
fbox{#1}}
begin{document}
chapter{Some chapter}
section{Section title}
Foo bar.
section*{Unnumbered section}
blindtext
end{document}
If you want finer control than what fbox
allows (fboxsep
and fboxrule
), using a tikzpicture
environment for the frame is a good alternative.
Thank you very much for helping me!
– Ravi
5 hours ago
add a comment |
A solution with a simple tabulary
:
documentclass[10pt, a4paper,svgnames, twoside]{report}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[showframe]{geometry}
usepackage{blindtext}
usepackage{array, tabulary}
usepackage[explicit]{titlesec}
usepackage{blindtext, xcolor}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[block]{Largebfseriessffamilysetlength{fboxrule}{1pt}color{SlateGrey}}{}{0pt}{fbox{begin{tabulary}{dimexprlinewidth-tabcolsep-fboxrule}{@{}l!{vline width 1.2pt}L}thesection  end{tabulary}} }
begin{document}
setcounter{chapter}{2}
section{Section Title. Some more more text to have a really very very long section title.}
blindtext
section{A much shorter section title}
blindtext
end{document}
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%2f482915%2fhow-to-add-frame-around-section-using-titlesec%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can have it with TikZ and explicit
option of titlesec
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
With very long section titles (with help from this question):
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
If you want to have "|" instead of "—", as in the attached figure, you can use textbar
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{textbar}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
However, a vertical line like this is much better I think.
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
usetikzlibrary{positioning}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikz[font=Largebfseries]{node[draw,minimum height=.75cm] (x) {thesection};node[minimum height=.75cm,below right=0pt and 0pt of x.north west,draw,max width=textwidth-.6666em-.4pt]{hspace{.3333em}phantom{thesection}hspace{.3333em}#1};}}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
Thanks a million!
– Ravi
5 hours ago
1
Nice answer. Maybe the relative positioning of TikZ nodes should use anchors on the baseline, andstrut
to ensure the top (resp. bottom) lines from section number and title nodes are at the same height, rather than north west and a hardcoded minimum height...
– frougon
3 hours ago
1
@frougon Thanks for the suggestion. Actually I use this way because I am not so familiar withanchor
. Maybe I will consider it when I have much free time.
– JouleV
3 hours ago
@JouleV I haven't expected so much. Thanks again.
– Ravi
1 hour ago
1
@Ravi You are welcome.
– JouleV
1 hour ago
add a comment |
You can have it with TikZ and explicit
option of titlesec
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
With very long section titles (with help from this question):
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
If you want to have "|" instead of "—", as in the attached figure, you can use textbar
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{textbar}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
However, a vertical line like this is much better I think.
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
usetikzlibrary{positioning}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikz[font=Largebfseries]{node[draw,minimum height=.75cm] (x) {thesection};node[minimum height=.75cm,below right=0pt and 0pt of x.north west,draw,max width=textwidth-.6666em-.4pt]{hspace{.3333em}phantom{thesection}hspace{.3333em}#1};}}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
Thanks a million!
– Ravi
5 hours ago
1
Nice answer. Maybe the relative positioning of TikZ nodes should use anchors on the baseline, andstrut
to ensure the top (resp. bottom) lines from section number and title nodes are at the same height, rather than north west and a hardcoded minimum height...
– frougon
3 hours ago
1
@frougon Thanks for the suggestion. Actually I use this way because I am not so familiar withanchor
. Maybe I will consider it when I have much free time.
– JouleV
3 hours ago
@JouleV I haven't expected so much. Thanks again.
– Ravi
1 hour ago
1
@Ravi You are welcome.
– JouleV
1 hour ago
add a comment |
You can have it with TikZ and explicit
option of titlesec
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
With very long section titles (with help from this question):
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
If you want to have "|" instead of "—", as in the attached figure, you can use textbar
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{textbar}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
However, a vertical line like this is much better I think.
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
usetikzlibrary{positioning}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikz[font=Largebfseries]{node[draw,minimum height=.75cm] (x) {thesection};node[minimum height=.75cm,below right=0pt and 0pt of x.north west,draw,max width=textwidth-.6666em-.4pt]{hspace{.3333em}phantom{thesection}hspace{.3333em}#1};}}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
You can have it with TikZ and explicit
option of titlesec
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
With very long section titles (with help from this question):
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{|}hsp#1};}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
If you want to have "|" instead of "—", as in the attached figure, you can use textbar
:
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikznode[draw,max width=textwidth-.6666em-.4pt]{Largebfseriesthesectionhsptextcolor{seccolor}{textbar}hsp#1};}
begin{document}
section{Section Name}
blindtext
end{document}
However, a vertical line like this is much better I think.
documentclass[10pt,a4paper,twoside]{report}
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{color}
usepackage{tikz}
usepackage{varwidth}
usepackage{calc}
usetikzlibrary{positioning}
tikzset{
max width/.style args={#1}{
execute at begin node={begin{varwidth}{#1}},
execute at end node={end{varwidth}}
}
}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}
[hang]
{Largebfseries}
{}
{0pt}
{tikz[font=Largebfseries]{node[draw,minimum height=.75cm] (x) {thesection};node[minimum height=.75cm,below right=0pt and 0pt of x.north west,draw,max width=textwidth-.6666em-.4pt]{hspace{.3333em}phantom{thesection}hspace{.3333em}#1};}}
begin{document}
section{Section Name}
blindtext
section{This is a very long section name that has to be broken into two lines}
end{document}
edited 4 hours ago
answered 6 hours ago


JouleVJouleV
10.1k22558
10.1k22558
Thanks a million!
– Ravi
5 hours ago
1
Nice answer. Maybe the relative positioning of TikZ nodes should use anchors on the baseline, andstrut
to ensure the top (resp. bottom) lines from section number and title nodes are at the same height, rather than north west and a hardcoded minimum height...
– frougon
3 hours ago
1
@frougon Thanks for the suggestion. Actually I use this way because I am not so familiar withanchor
. Maybe I will consider it when I have much free time.
– JouleV
3 hours ago
@JouleV I haven't expected so much. Thanks again.
– Ravi
1 hour ago
1
@Ravi You are welcome.
– JouleV
1 hour ago
add a comment |
Thanks a million!
– Ravi
5 hours ago
1
Nice answer. Maybe the relative positioning of TikZ nodes should use anchors on the baseline, andstrut
to ensure the top (resp. bottom) lines from section number and title nodes are at the same height, rather than north west and a hardcoded minimum height...
– frougon
3 hours ago
1
@frougon Thanks for the suggestion. Actually I use this way because I am not so familiar withanchor
. Maybe I will consider it when I have much free time.
– JouleV
3 hours ago
@JouleV I haven't expected so much. Thanks again.
– Ravi
1 hour ago
1
@Ravi You are welcome.
– JouleV
1 hour ago
Thanks a million!
– Ravi
5 hours ago
Thanks a million!
– Ravi
5 hours ago
1
1
Nice answer. Maybe the relative positioning of TikZ nodes should use anchors on the baseline, and
strut
to ensure the top (resp. bottom) lines from section number and title nodes are at the same height, rather than north west and a hardcoded minimum height...– frougon
3 hours ago
Nice answer. Maybe the relative positioning of TikZ nodes should use anchors on the baseline, and
strut
to ensure the top (resp. bottom) lines from section number and title nodes are at the same height, rather than north west and a hardcoded minimum height...– frougon
3 hours ago
1
1
@frougon Thanks for the suggestion. Actually I use this way because I am not so familiar with
anchor
. Maybe I will consider it when I have much free time.– JouleV
3 hours ago
@frougon Thanks for the suggestion. Actually I use this way because I am not so familiar with
anchor
. Maybe I will consider it when I have much free time.– JouleV
3 hours ago
@JouleV I haven't expected so much. Thanks again.
– Ravi
1 hour ago
@JouleV I haven't expected so much. Thanks again.
– Ravi
1 hour ago
1
1
@Ravi You are welcome.
– JouleV
1 hour ago
@Ravi You are welcome.
– JouleV
1 hour ago
add a comment |
Solution based on fbox
, using textbar
for the vertical bar, and with a variant for unnumbered sections (section*
):
documentclass[10pt,a4paper,twoside]{report}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{blindtext}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
newcommand*{sectionFont}{%
Largebfseries
}
% For section
titleformat{section}[block]{sectionFont}{}{0pt}{%
fbox{thesection hsp textcolor{seccolor}{textbar}hsp #1}}
% For section*
titleformat{name=section, numberless}[block]{sectionFont}{}{0pt}{%
fbox{#1}}
begin{document}
chapter{Some chapter}
section{Section title}
Foo bar.
section*{Unnumbered section}
blindtext
end{document}
If you want finer control than what fbox
allows (fboxsep
and fboxrule
), using a tikzpicture
environment for the frame is a good alternative.
Thank you very much for helping me!
– Ravi
5 hours ago
add a comment |
Solution based on fbox
, using textbar
for the vertical bar, and with a variant for unnumbered sections (section*
):
documentclass[10pt,a4paper,twoside]{report}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{blindtext}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
newcommand*{sectionFont}{%
Largebfseries
}
% For section
titleformat{section}[block]{sectionFont}{}{0pt}{%
fbox{thesection hsp textcolor{seccolor}{textbar}hsp #1}}
% For section*
titleformat{name=section, numberless}[block]{sectionFont}{}{0pt}{%
fbox{#1}}
begin{document}
chapter{Some chapter}
section{Section title}
Foo bar.
section*{Unnumbered section}
blindtext
end{document}
If you want finer control than what fbox
allows (fboxsep
and fboxrule
), using a tikzpicture
environment for the frame is a good alternative.
Thank you very much for helping me!
– Ravi
5 hours ago
add a comment |
Solution based on fbox
, using textbar
for the vertical bar, and with a variant for unnumbered sections (section*
):
documentclass[10pt,a4paper,twoside]{report}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{blindtext}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
newcommand*{sectionFont}{%
Largebfseries
}
% For section
titleformat{section}[block]{sectionFont}{}{0pt}{%
fbox{thesection hsp textcolor{seccolor}{textbar}hsp #1}}
% For section*
titleformat{name=section, numberless}[block]{sectionFont}{}{0pt}{%
fbox{#1}}
begin{document}
chapter{Some chapter}
section{Section title}
Foo bar.
section*{Unnumbered section}
blindtext
end{document}
If you want finer control than what fbox
allows (fboxsep
and fboxrule
), using a tikzpicture
environment for the frame is a good alternative.
Solution based on fbox
, using textbar
for the vertical bar, and with a variant for unnumbered sections (section*
):
documentclass[10pt,a4paper,twoside]{report}
usepackage{xcolor}
usepackage[explicit]{titlesec}
usepackage{blindtext}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
newcommand*{sectionFont}{%
Largebfseries
}
% For section
titleformat{section}[block]{sectionFont}{}{0pt}{%
fbox{thesection hsp textcolor{seccolor}{textbar}hsp #1}}
% For section*
titleformat{name=section, numberless}[block]{sectionFont}{}{0pt}{%
fbox{#1}}
begin{document}
chapter{Some chapter}
section{Section title}
Foo bar.
section*{Unnumbered section}
blindtext
end{document}
If you want finer control than what fbox
allows (fboxsep
and fboxrule
), using a tikzpicture
environment for the frame is a good alternative.
edited 5 hours ago
answered 6 hours ago
frougonfrougon
696611
696611
Thank you very much for helping me!
– Ravi
5 hours ago
add a comment |
Thank you very much for helping me!
– Ravi
5 hours ago
Thank you very much for helping me!
– Ravi
5 hours ago
Thank you very much for helping me!
– Ravi
5 hours ago
add a comment |
A solution with a simple tabulary
:
documentclass[10pt, a4paper,svgnames, twoside]{report}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[showframe]{geometry}
usepackage{blindtext}
usepackage{array, tabulary}
usepackage[explicit]{titlesec}
usepackage{blindtext, xcolor}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[block]{Largebfseriessffamilysetlength{fboxrule}{1pt}color{SlateGrey}}{}{0pt}{fbox{begin{tabulary}{dimexprlinewidth-tabcolsep-fboxrule}{@{}l!{vline width 1.2pt}L}thesection  end{tabulary}} }
begin{document}
setcounter{chapter}{2}
section{Section Title. Some more more text to have a really very very long section title.}
blindtext
section{A much shorter section title}
blindtext
end{document}
add a comment |
A solution with a simple tabulary
:
documentclass[10pt, a4paper,svgnames, twoside]{report}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[showframe]{geometry}
usepackage{blindtext}
usepackage{array, tabulary}
usepackage[explicit]{titlesec}
usepackage{blindtext, xcolor}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[block]{Largebfseriessffamilysetlength{fboxrule}{1pt}color{SlateGrey}}{}{0pt}{fbox{begin{tabulary}{dimexprlinewidth-tabcolsep-fboxrule}{@{}l!{vline width 1.2pt}L}thesection  end{tabulary}} }
begin{document}
setcounter{chapter}{2}
section{Section Title. Some more more text to have a really very very long section title.}
blindtext
section{A much shorter section title}
blindtext
end{document}
add a comment |
A solution with a simple tabulary
:
documentclass[10pt, a4paper,svgnames, twoside]{report}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[showframe]{geometry}
usepackage{blindtext}
usepackage{array, tabulary}
usepackage[explicit]{titlesec}
usepackage{blindtext, xcolor}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[block]{Largebfseriessffamilysetlength{fboxrule}{1pt}color{SlateGrey}}{}{0pt}{fbox{begin{tabulary}{dimexprlinewidth-tabcolsep-fboxrule}{@{}l!{vline width 1.2pt}L}thesection  end{tabulary}} }
begin{document}
setcounter{chapter}{2}
section{Section Title. Some more more text to have a really very very long section title.}
blindtext
section{A much shorter section title}
blindtext
end{document}
A solution with a simple tabulary
:
documentclass[10pt, a4paper,svgnames, twoside]{report}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[showframe]{geometry}
usepackage{blindtext}
usepackage{array, tabulary}
usepackage[explicit]{titlesec}
usepackage{blindtext, xcolor}
definecolor{seccolor}{RGB}{41,48,57}
newcommand{hsp}{hspace{8pt}}
titleformat{section}[block]{Largebfseriessffamilysetlength{fboxrule}{1pt}color{SlateGrey}}{}{0pt}{fbox{begin{tabulary}{dimexprlinewidth-tabcolsep-fboxrule}{@{}l!{vline width 1.2pt}L}thesection  end{tabulary}} }
begin{document}
setcounter{chapter}{2}
section{Section Title. Some more more text to have a really very very long section title.}
blindtext
section{A much shorter section title}
blindtext
end{document}
answered 42 mins ago
BernardBernard
175k776207
175k776207
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%2f482915%2fhow-to-add-frame-around-section-using-titlesec%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
nst,QD3hevYZaEIz