TransWikia.com

Move chapter title to the top left of page

TeX - LaTeX Asked by Seddon016 on July 26, 2021

I am trying to create a document in latex but I am having difficulties with the chapter location.

On each page of my document I want one chapter, but I want to have it in the top left of the page. However, in my attempt there seems to be a big white gap.

Below is a screenshot of what I am seeing
enter image description here
enter image description here

Here is my code:

documentclass
[oneside,landscape,tikz,border=2pt,png]
{book}
usepackage{xcolor}
usepackage{blindtext}
usepackage{tikz}
usepackage{smartdiagram}

usepackage[absolute,overlay]{textpos}
setlength{TPHorizModule}{1mm}
setlength{TPVertModule}{1mm}
usetikzlibrary{shapes.symbols}

tikzset{sequence item/.append style={
        /utils/exec={ifnumxi=1
            tikzset{signal from=nowhere}
            fi
        }
    }
}

usepackage[left=0.2in,right=0.2in,bottom=0.5in]{geometry}


usepackage[
automark,
autooneside=false,
markcase=noupper,
headsepline,
headwidth=thetextwidth+12mm:-5mm,
]{scrlayer-scrpage}
clearpairofpagestyles
rehead{leftmark}
lohead{rightmark}
ohead{pagemark}
renewcommandchaptermarkformat{}% no chapternumber in header
setkomafont{pageheadfoot}{normalfont}
renewcommand*{pagemark}{{usekomafont{pagenumber}{thepage}}}

% define new layers
DeclareNewLayer[
background,
oddpage,
align=tr,
hoffset=paperwidth,
voffset=0pt,%distance from top
width=1cm,% width of the swatch
height=dimexprvoffset+1in+topmargin+headheightrelax,% height of the swatch
contents={textcolor{swatchcolor}{rule{layerwidth}{layerheight}}}
]{swatch.odd}
DeclareNewLayer[
clone=swatch.odd,
evenpage,
align=l,
hoffset=0pt
]{swatch.even}

DeclareNewLayer[
foreground,
oddpage,
align=br,
hoffset=paperwidth,
voffset=paperheight,
width=3em,
height=2baselineskip,
contents={{%
        setlength{fboxsep}{0pt}%
        colorbox{white}{parbox[c][layerheight][c]{layerwidth}{centeringpagemark}}%
}}
]{pagenumberouterbottom.odd}
DeclareNewLayer[
clone=pagenumberouterbottom.odd,
evenpage,
align=bl,
hoffset=0pt
]{pagenumberouterbottom.even}
addtokomafont{pagenumber}{color{black}bfseries}
AddLayersToPageStyle{scrheadings}{pagenumberouterbottom.odd,pagenumberouterbottom.even}
AddLayersToPageStyle{plain}{pagenumberouterbottom.odd,pagenumberouterbottom.even}

% add layers to every pagestyle
AddLayersToPageStyle{@everystyle@}{swatch.odd,swatch.even}

newcommandswatchcolor[1]{colorlet{swatchcolor}{#1}}
swatchcolor{white}

%Font

usepackage{carlito}
usepackage{fontspec}
setmainfont{Carlito}



begin{document}
    tableofcontents
    newpage
    vspace{-2in}
    chapter*{First chapter}swatchcolor{red}
    
    Blindtext[1]
    
    newpage
    chapter{Second chapter}swatchcolor{blue}

    Blindtext[1]
    
    chapter{Third chapter}swatchcolor{green}

    Blindtext[1]
    
end{document}

One Answer

By messing around with the top option provided by the geometry package I've come up with this: hard fix which is a fix, but it is not really pleasing and it changes the page format globally (as you can see the red rectangle in the top right corner is now gone).

Another way of removing the whitespace is through the titlesec package.

I personally do not see any issues with the title being in the centre of the page (I also think it's an intended feature). If you're trying to achieve a presentation style it would be better to use the beamer class.

Why not use the standard portrait page format?

Code

usepackage{geometry}
geometry{
    top = -2cm,
    left=0.2in,
    right=0.2in,
    bottom=0.5in
}
usepackage{titlesec}
titlespacing*{chapter}{0pt}{-150pt}{40pt}

Answered by sRaviolii on July 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP