Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove chapter margin in LaTeX

Tags:

latex

overleaf

I've a big problem with LaTeX, because I can't delete margin before new chapter

screenshot

I've tried everything but I am rather new and I didn't manage. My code:

\documentclass[polish,12pt,oneside]{mwbk}
\usepackage[a4paper,includeheadfoot,inner=3.0cm,outer=2.5cm,top=3cm,bottom=3cm]{geometry}
\linespread{1.416}
\usepackage{lipsum}
\clubpenalty=10000
\widowpenalty=10000

\usepackage{fancyhdr}
\pagestyle{plain}
\setlength{\headsep}{2em}
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}

\usepackage[utf8]{inputenc} 
\usepackage[polish]{babel}
\usepackage{polski}

\usepackage[pagebackref=false]{hyperref}
\bibliographystyle{plplain}
\usepackage{dirtree}
\usepackage{varwidth}
\usepackage[labelsep=period]{caption} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage{subcaption}
\usepackage{float}
\usepackage{wasysym}


% THE CODE I'VE TRIED
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
% --- Patch \chapter
\patchcmd{\@makechapterhead}{50\p@}{\chapheadtopskip}{}{}% Space from top of page to CHAPTER X
\patchcmd{\@makechapterhead}{20\p@}{\chapheadsep}{}{}% Space between CHAPTER X and CHAPTER TITLE
\patchcmd{\@makechapterhead}{40\p@}{\chapheadbelowskip}{}{}% Space between CHAPTER TITLE and text
% --- Patch \chapter*
\patchcmd{\@makeschapterhead}{50\p@}{\chapheadtopskip}{}{}% Space from top of page to CHAPTER TITLE
\patchcmd{\@makeschapterhead}{40\p@}{\chapheadbelowskip}{}{}% SPace between CHAPTER TITLE and text
\makeatother
% Set new lengths
\newlength{\chapheadtopskip}\setlength{\chapheadtopskip}{5pt}
\newlength{\chapheadsep}\setlength{\chapheadsep}{5pt}
\newlength{\chapheadbelowskip}\setlength{\chapheadbelowskip}{5pt}
% END THE CODE I'VE TRIED


\begin{document}

\selectlanguage{polish}

\addtocounter{page}{1}    
\setcounter{tocdepth}{1}  
\tableofcontents  

\setlength{\parskip}{0.5ex}


\chapter{Hardware}
\label{ch:hardware}

\section{Components}
\label{sec:components}
\lipsum[3-7]


\cleardoublepage
\phantomsection
\listoffigures

\end{document}

Methods with titlesec package give me bunch of errors. I'm using overleaf.

changing

\documentclass[polish,12pt,oneside]{mwbk}

to

\documentclass[polish,12pt,oneside]{book}

helps, but destroy another styling (like enum list etc.)

like image 251
bartosz325 Avatar asked Oct 15 '22 21:10

bartosz325


1 Answers

The class you use, defines the chapter format with

\SetSectionFormatting[breakbefore,wholewidth]{chapter}
        {0\p@}
        {\FormatRigidChapterHeading{6.4\baselineskip}{12\p@}%
           {\large\@chapapp\space}{\LARGE}}
        {1.6\baselineskip}

If you play around with the value for 6.4, you can adjust the space above the chapter heading.

\documentclass[polish,12pt,oneside]{mwbk}
\usepackage[a4paper,includeheadfoot,inner=3.0cm,outer=2.5cm,top=3cm,bottom=3cm]{geometry}
\linespread{1.416}
\usepackage{lipsum}
\clubpenalty=10000
\widowpenalty=10000

\usepackage{fancyhdr}
\pagestyle{plain}
\setlength{\headsep}{2em}
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}

\usepackage[utf8]{inputenc} 
\usepackage[polish]{babel}
\usepackage{polski}

\usepackage[pagebackref=false]{hyperref}
\bibliographystyle{plplain}
\usepackage{dirtree}
\usepackage{varwidth}
\usepackage[labelsep=period]{caption} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage{subcaption}
\usepackage{float}
\usepackage{wasysym}


% THE CODE I'VE TRIED
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
% --- Patch \chapter
\patchcmd{\@makechapterhead}{50\p@}{\chapheadtopskip}{}{}% Space from top of page to CHAPTER X
\patchcmd{\@makechapterhead}{20\p@}{\chapheadsep}{}{}% Space between CHAPTER X and CHAPTER TITLE
\patchcmd{\@makechapterhead}{40\p@}{\chapheadbelowskip}{}{}% Space between CHAPTER TITLE and text
% --- Patch \chapter*
\patchcmd{\@makeschapterhead}{0\p@}{\chapheadtopskip}{}{}% Space from top of page to CHAPTER TITLE
\patchcmd{\@makeschapterhead}{40\p@}{\chapheadbelowskip}{}{}% SPace between CHAPTER TITLE and text
\makeatother
% Set new lengths
\newlength{\chapheadtopskip}\setlength{\chapheadtopskip}{5pt}
\newlength{\chapheadsep}\setlength{\chapheadsep}{5pt}
\newlength{\chapheadbelowskip}\setlength{\chapheadbelowskip}{5pt}
% END THE CODE I'VE TRIED

\makeatletter
\SetSectionFormatting[breakbefore,wholewidth]{chapter}
        {0\p@}
        {\FormatRigidChapterHeading{0\baselineskip}{12\p@}%
           {\large\@chapapp\space}{\LARGE}}
        {1.6\baselineskip}
\makeatother

\begin{document}

\selectlanguage{polish}

\addtocounter{page}{1}    
\setcounter{tocdepth}{1}  
\tableofcontents  

\setlength{\parskip}{0.5ex}


\chapter{Hardware}
\label{ch:hardware}

\section{Components}
\label{sec:components}
\lipsum[3-7]


\cleardoublepage
\phantomsection
\listoffigures

\end{document}

enter image description here

like image 181
samcarter_is_at_topanswers.xyz Avatar answered Oct 29 '22 07:10

samcarter_is_at_topanswers.xyz