Text Formatting\hspace before \section

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
mike1264
Posts: 27
Joined: Wed Jul 24, 2013 6:07 pm

\hspace before \section

Post by mike1264 »

Hi,
I would like to add a space before a section heading.

I have tried:

Code: Select all

\hspace[*]{5pt}\setkomafont{section}{\fontsize{45}{40}\selectfont\fontspec{Mathilde}}
unsuccessfully. I realise that Latex usually discards white space at the start of a line e.g. a section heading.

I would appreciate any pointers how I may achieve a space before a section heading of 0.5 inches.

Code: Select all

\documentclass[11pt,english,british,twoside,openany]{scrbook}
\usepackage{mystyle}

\begin{document}

	 \title{\mytitle}
        \author{}
        \date{}

\frontmatter
\maketitle
        \begin{titlepage}
                \begin{flushright}
        {\huge \mytitle}
        \par\end{flushright}{\huge \par}
        \end{titlepage}

        \begin{titlepage}
                \noindent\includegraphics[width=4in,height=2in]{../img/titr_ben_sig}
                \vspace*{0.5in}
                \begin{flushright}
        \Huge{Tears in the Rain}
        \par\end{flushright}{\Huge \par}

        \clearpage
        \thispagestyle{empty}

		\begin{center}
        		\emph{Copyright}
		\end{center}
		\begin{center}
        		\textcopyright{ 2014 Ben Francis All rights reserved.}
		\end{center}
		\vspace*{0.5in}
		\begin{center}
        \begin{minipage}[t]{0.5\paperwidth}
        \end{minipage}
		\end{center}
		\vspace*{0.5in}
		\begin{center}
        		ISBN:
		\end{center}
		\vspace*{0.2in}
		\begin{center}
        		A CIP Record for this book is available from the British
        Library.
		\end{center}
		\vspace*{0.1in}
		\begin{center}
        		Typeset in \LaTeXe
		\end{center}
	\end{titlepage}

\pagenumbering{gobble}% Remove page numbers (and reset to 1)
	\tableofcontents

\input{matter.tex}
		
\end{document}
My style file is:

Code: Select all

\ProvidesPackage{mystyle}
\usepackage{lettrine}
%\usepackage{blindtext}
\usepackage[automark,headsepline,footsepline=.25pt]{scrlayer-scrpage}
\usepackage{microtype}
\usepackage{ragged2e}
\usepackage{graphicx}
\graphicspath{ {../img/} }
\usepackage{wrapfig}
\usepackage[british]{babel}
\pagestyle{scrheadings}
\addtokomafont{pageheadfoot}{\slshape}
\addtokomafont{pagehead}{\normalsize}
\addtokomafont{pagefoot}{\normalsize}
\addtokomafont{disposition}{\rmfamily}% rm for chapter headings
%\addtokomafont{trajon pro}{\rmfamily}
%\ohead{\pagemark} %Page Number
%\ihead{\mytitle} %Book Title
\chead{\textbf {Ben Francis}}
\ofoot{} %Author Name
\ifoot{} % Chapter Number
\lehead{\textbf \pagemark}
%\cehead{Ben Francis}
\rohead{\textbf \pagemark}
\cohead{\textbf {\mytitle}}
\setkomafont{section}{\textit}{\normalsize}
\renewcommand\thepart{\Alph{part}}
\usepackage{fontspec}
\linespread{1.05}
\parindent=0.25in
\parskip=2pt
%removes overrun on outside margin
\usepackage{hyphenat}
\tolerance=1000
\hyphenpenalty=1000
\setmainfont{Linux Libertine O} %clear font, typographers quote marks
\renewcommand*{\partpagestyle}{empty}
\usepackage{geometry}
\geometry{paperwidth=5.06in,paperheight=7.81in,
	verbose,
	tmargin=0.75in,
	bmargin=0.75in,
	inner=0.75in,
	outer=0.5in,
	headheight=0.1in,
	headsep=0.15in,
	footskip=0.45in,
	twoside}
\newcommand{\mytitle}{Tears in the Rain} 
\newcommand{\emptx}[1]{\textit{#1}}

%Add space above chapter titles
\usepackage{titlesec}

\titleformat{\chapter}[display]
    {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\normalsize}
\titlespacing*{\chapter}{0pt}{25pt}{1pt}%Second number changes space
                                %amount

\hspace[*]{5pt}\setkomafont{section}{\fontsize{45}{40}\selectfont\fontspec{Mathilde}}
\setkomafont{subsection}{\small}
\setkomafont{subsubsection}{\small}
\setkomafont{paragraph}{\normalsize}
\setkomafont{subparagraph}{\normalsize}
Last edited by Stefan Kottwitz on Thu Sep 24, 2015 8:54 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

\hspace before \section

Post by Johannes_B »

Finally came around fixing your stuff. What you are looking for is all doable with KOMA-script.

You are (were) using package titlesec to format the chapters, why aren't you trying to customize the sections as well?

Either way, here are a few suggestions:

Code: Select all

\documentclass[11pt,english,british,twoside,openany,demo]{scrbook}
%    \ProvidesPackage{mystyle}
\usepackage{lettrine}
\usepackage[automark,headsepline,footsepline=.25pt]{scrlayer-scrpage}
\usepackage{microtype}
\usepackage{ragged2e}
\usepackage{graphicx}
\graphicspath{ {../img/} }
\usepackage{wrapfig}
\usepackage[british]{babel}
\pagestyle{scrheadings}
\addtokomafont{pageheadfoot}{\slshape}
\addtokomafont{pagehead}{\normalsize}
\addtokomafont{pagefoot}{\normalsize}
\addtokomafont{disposition}{\rmfamily}% rm for chapter headings
							    %\addtokomafont{trajon pro}{\rmfamily}
							    %\ohead{\pagemark} %Page Number
							    %\ihead{\mytitle} %Book Title
\chead{\textbf {Ben Francis}}
\ofoot{} %Author Name
\ifoot{} % Chapter Number

\addtokomafont{pagenumber}{\bfseries}
\ohead{\pagemark}
%\lehead{\textbf \pagemark}%Don't do it like that. See lines above
%\cehead{Ben Francis}
%\rohead{\textbf \pagemark}
\cohead{\textbf{\mytitle}}%Seems you want to have everything in
%the header in boldface. How about
\addtokomafont{pagehead}{\bfseries}
\setkomafont{section}{\textit}{\normalsize}%That doesn't make any sense
\renewcommand\thepart{\Alph{part}}
\usepackage{fontspec}
\linespread{1.05}
\setlength{\parindent}{.25in}
\setlength{\parskip}{2pt plus 1pt minus 1pt}
%\parindent=0.25in
%\parskip=2pt% this is teX
\usepackage{hyphenat}
\tolerance=1000
\hyphenpenalty=1000
\setmainfont{Linux Libertine O} %clear font, typographers quote marks
\renewcommand*{\partpagestyle}{empty}
\usepackage{geometry}
\geometry{paperwidth=5.06in,paperheight=7.81in,
	verbose,
	tmargin=0.75in,
	bmargin=0.75in,
	inner=0.75in,
	outer=0.5in,
	headheight=0.1in,
	headsep=0.15in,
	footskip=0.45in,
twoside}
\newcommand{\mytitle}{Tears in the Rain}
\newcommand{\emptx}[1]{\textit{#1}}

%Add space above chapter titles
%\usepackage{titlesec}

\RedeclareSectionCommand[font={\normalfont\huge\bfseries},
beforeskip=0pt,
afterskip=25pt,
]{chapter}
% set the values to your liking

\setkomafont{section}{\fontsize{45}{40}\selectfont\fontspec{Latin Modern Sans}}
%Are you sure about that? That big?
\setkomafont{subsection}{\small}
\setkomafont{subsubsection}{\small}
\setkomafont{paragraph}{\normalsize}
\setkomafont{subparagraph}{\normalsize}
%\usepackage{mystyle}
\usepackage{blindtext}

\RedeclareSectionCommand[font={\normalfont\bfseries},%<- this
%	overrides the insane font-size
indent=1in% indents each section by one in
]{section}
%\renewcommand{\raggedsection}{\centering}% centers the sections
\begin{document}



%Completely unrelated stuff



%\pagenumbering{gobble}% Remove page numbers (and reset to 1)
%JB: Very bad style to reset the pagenumbering. They are not
%shown for titlepages either
\tableofcontents

\blinddocument
\blinddocument
\blinddocument

\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply