-1

I found this document with the following section style and header:

chapter 1, Introduction

Header

I am a true newbie at latex, is there a way I can do something similar? This personalized "section title" and this header, which indicates the section the page belongs to?

(In the 1st image, it says "Chapter 1" and the section is "Introduction") (In the 2nd image, the section "Introduction" is shown at the header)

Thanks!

---- EDIT -----

Question to Alan Xiang

Now

Is there a way to change from

"1.1.1 Some Subsection"

to

"1.1 Some Subsection"

??

Detail: "Chapter 1" is merely decorative, it does not need to be a structure (if that matters).

Thanks!

  • 1
    Welcome to TeX SX! You should take look at the titlesec package documentation and its companion package titleps. – Bernard Jul 31 at 14:08
  • He should take first a look to what is a minimal working example (MWE). – Fran Aug 1 at 17:06
3

Fairly simple using memoir:

\documentclass{memoir}
\usepackage[portuguese]{babel}
\usepackage{lipsum}
\chapterstyle{bianchi}
\begin{document}
\chapter{Introduç\~ao}
\section{Some subsection}
\lipsum
\end{document}

mwe

| improve this answer | |
  • @Joseph I understand you, the same thing happens to me when people with English keyboards type \~n instead of ñ in a text in Spanish, for instance, but my keyboard is not Portuguese, so for me, type \~a is just munch faster than look up the corresponding uft8 code. – Fran Aug 2 at 5:38
0

If you are using KOMA-Script document classes (which are nice replacements for standard ones like article, report), these questions provide some clue on how to reproduce the title:

The header can be customized with scrlayer-scrpage package.

enter image description here

The code is as follows:

\documentclass[DIV=10]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{scrlayer-scrpage}
\usepackage{expl3}
\usepackage{blindtext} % dummy text
\usepackage{mdframed}

\makeatletter
\ExplSyntaxOn

\bool_new:N \l_processed_bool

% redefine section title
\renewcommand{\sectionlinesformat}[4]{

    \bool_set_false:N \l_processed_bool
    
    \str_if_eq:nnT {#1} {section} {
        \begin{mdframed}[leftline=false, rightline=false, linewidth=0.8pt, innertopmargin=5mm, innerbottommargin=5mm, leftmargin=1cm, rightmargin=1cm]
        \centering\@hangfrom{\hskip #2}{#4}\par
        \end{mdframed}
        \bool_set_true:N \l_processed_bool
    }
    
    \bool_if:nT {!\l_processed_bool} {
        % use default style
        \@hangfrom{\hskip #2#3}{#4}
    }

}

% redefine chapter title
\renewcommand{\chapterlinesformat}[3]{

    \bool_set_false:N \l_processed_bool
    
    \str_if_eq:nnT {#1} {chapter} {
        \begin{center}
            Chapter~#2
        \end{center}
        \vspace*{-6mm} % reduce spacing
        \bool_set_true:N \l_processed_bool
    }
    
    \bool_if:nT {!\l_processed_bool} {
        % use default style
        \@hangfrom{#2}{#3}
    }

}

\tl_new:N \l_section_number_tl
% by default, the section numering is chapter.section
% we need to delete the chapter index here
\cs_set:Npn \fix_section_number:n #1 {
    \tl_set:Nx \l_section_number_tl {#1}
    \regex_replace_once:nnN {[0-9]+\.} {} \l_section_number_tl
}


% change chapter font
\addtokomafont{chapter}{\normalfont\Large\itshape}

% set header
\chead{}
\renewcommand{\sectionmark}[1]{
    \fix_section_number:n{\thesection}
    \markright{\l_section_number_tl .\ #1}
} 
\ohead{\scshape \rightmark}
\ihead{\pagemark}

% disable page number
\cfoot{}

% activate head sep line
\KOMAoption{headsepline}{0.5pt}

% suppress page numbering on chapter start pages
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{om}{
    \IfValueTF{#1}{
        \oldchapter[#1]{#2}
    }{
        \oldchapter{#2}
    }
    \thispagestyle{empty}
}

\ExplSyntaxOff
\makeatother

\begin{document}
    \chapter{Some Chapter}
    \section{Introduction}
    \Blindtext[9]
    \section{More Introduction}
    \Blindtext[8]
\end{document}

Update

If you want to modify subsection styles, you can modify \sectionlinesformat. Everything works properly except from table of contents-more work needs to be done to correct it.

\documentclass[DIV=10]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{scrlayer-scrpage}
\usepackage{expl3}
\usepackage{blindtext} % dummy text
\usepackage{mdframed}

\makeatletter
\ExplSyntaxOn

\bool_new:N \l_processed_bool

\tl_new:N \l_section_number_tl
% by default, the section numering is chapter.section
% we need to delete the chapter index here
\cs_set:Npn \fix_section_number:n #1 {
    \tl_set:Nx \l_section_number_tl {#1}
    \regex_replace_once:nnN {[0-9]+\.} {} \l_section_number_tl
}

% redefine section title
\renewcommand{\sectionlinesformat}[4]{

    \bool_set_false:N \l_processed_bool
    
    \str_if_eq:nnT {#1} {section} {
        \begin{mdframed}[leftline=false, rightline=false, linewidth=0.8pt, innertopmargin=5mm, innerbottommargin=5mm, leftmargin=1cm, rightmargin=1cm]
        \centering\@hangfrom{\hskip #2}{#4}\par
        \end{mdframed}
        \bool_set_true:N \l_processed_bool
    }
    \str_if_eq:nnT {#1} {subsection} {
        \fix_section_number:n {#3}
        \@hangfrom{\hskip #2\l_section_number_tl}{#4}
        \bool_set_true:N \l_processed_bool
    }
    
    \bool_if:nT {!\l_processed_bool} {
        % use default style
        \@hangfrom{\hskip #2#3}{#4}
    }

}

% redefine chapter title
\renewcommand{\chapterlinesformat}[3]{

    \bool_set_false:N \l_processed_bool
    
    \str_if_eq:nnT {#1} {chapter} {
        \begin{center}
            Chapter~#2
        \end{center}
        \vspace*{-6mm} % reduce spacing
        \bool_set_true:N \l_processed_bool
    }
    
    \bool_if:nT {!\l_processed_bool} {
        % use default style
        \@hangfrom{#2}{#3}
    }

}


% change chapter font
\addtokomafont{chapter}{\normalfont\Large\itshape}

% set header
\chead{}
\renewcommand{\sectionmark}[1]{
    \fix_section_number:n{\thesection}
    \markright{\l_section_number_tl .\ #1}
} 
\ohead{\scshape \rightmark}
\ihead{\pagemark}

% disable page number
\cfoot{}

% activate head sep line
\KOMAoption{headsepline}{0.5pt}

% suppress page numbering on chapter start pages
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{som}{
    \IfValueTF{#2}{
        \IfBooleanTF{#1}{
            \oldchapter*[#2]{#3}
        } {
            \oldchapter[#2]{#3}
        }
    }{
        \IfBooleanTF{#1}{
            \oldchapter*{#3}
        } {
            \oldchapter{#3}
        }
    }
    \thispagestyle{empty}
}

\ExplSyntaxOff
\makeatother

\begin{document}
    \chapter{Some Chapter}
    \section{Introduction}
    \subsection{Subsection}
    \Blindtext[9]
    \section{More Introduction}
    \Blindtext[8]
\end{document}
| improve this answer | |
  • Thanks! Works great! There's just one detail: \chapter{Chapter 1} \section{Introduction} \subsection{Some Subsection} it prints: Chapter 1 Introduction 1.1.1 Some Subsection Is there a way that instead of "1.1.1" it shows only "1.1" ?? 1.1 Some Subsection – Bruno Sanches Aug 1 at 15:38
  • I will edit the post and make the same question there, as I think it might not be clear in the comment. – Bruno Sanches Aug 1 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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