0

I produce the following custom section titles:

enter image description here

There is quite a bit of stuff that is hardcoded (i.e. requires me to eyeball it) in here, which makes me nervous.

  1. Why are the two vrules not the same width (they both have 3pt thickness)? This problem goes away if I change \titlespacing\section{6.8in}{0in}{0in} to \titlespacing\section{6.0in}{0in}{0in}, but I don't know why it's happening.
  2. How do I ensure that the right-aligned title is flush to the margin? Now, it's manually done using the 6.67in value (width of a4 paper - width of left margin - width of right margin = 8.27 - 0.8 - 0.8 = 6.67), but for some reason, the space on the right looks bigger than on the left.
  3. How do I ensure a similar space between the vrule and text for both? Now, it's manually done using \hspace and I am sure they are not the same.

I really appreciate all input - doing things manually makes me very antsy.


MEW for above:

% these define the type of document and the look of the page
\documentclass[]{article}
\usepackage{lmodern}
\usepackage[toc,page]{appendix}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\usepackage[margin=0.8in, top = 1.3in, headheight = 0.6in]{geometry}
%\usepackage[bottom, flushmargin]{footmisc}
\setlength{\footnotesep}{\baselineskip} % space between footnotes 
\setlength{\parindent}{0pt} % space at start of paragraph
\setlength{\parskip}{0.14in} % space between paragraphs
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}

% colors
\usepackage{tcolorbox}
\usepackage{color} % colors
\usepackage{xcolor, colortbl} % more control over colors
\definecolor{c1}{HTML}{122084}

% heading formats
\usepackage[explicit]{titlesec}
\titlespacing\subsection{0pt}{0.21in}{0.01in}
\titlespacing\subsubsection{0pt}{0.21in}{0in}


% table-related
\usepackage{array}
\usepackage{booktabs}
\usepackage{multicol, makecell}
\usepackage{multirow, hhline}
\usepackage{siunitx}
\newcommand\bstrut{\rule{0pt}{2.5ex}} % space before row
\newcommand\astrut{\rule[-1.25ex]{0pt}{0pt}} % space after row
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}


\begin{document}

\thispagestyle{plain}

\newcommand{\hsp}{\hspace{-10.7cm}}
\titlespacing\section{6.67in}{0in}{0in}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{\color{c1}}{20pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt}>{\hsp}r}#1\end{tabular}}

\section*{An Internationally \\ Renowned Title}

\vspace{0.5in}

\renewcommand{\hsp}{\hspace{20pt}}
\titlespacing\section{0cm}{0in}{0in}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{\color{c1}}{20pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt}>{\hsp}l}#1\end{tabular}}

\section*{An Internationally \\ Renowned Title}

\end{document}
4
  • For the title aligned at the right margin, must the vertical rule be on the left, or on the right (i.e. the rule at the right margin)?
    – Bernard
    Commented May 10, 2020 at 10:26
  • At the right please (as shown).
    – Thev
    Commented May 10, 2020 at 10:31
  • And do you have any numbered sections, possibly with a different layout?
    – Bernard
    Commented May 10, 2020 at 10:34
  • None at all. Don't have to account for those.
    – Thev
    Commented May 10, 2020 at 10:37

1 Answer 1

1

It was more efficient to use the relevant tool among the alignment tools provided by the package (\filleft, \filright and filcenter). I took the opportunity to simplify a bit your code – needless to load color if you load xcolor and loading the latter with option [table] will spare you having to load colortbl (in this case, load tcolorbox afterwards, to avoid an option clash).

% these define the type of document and the look of the page
\documentclass[a4paper]{article}
\usepackage{lmodern}
\usepackage[toc,page]{appendix}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\usepackage[margin=0.8in, top=1.3in, headheight=0.6in, showframe]{geometry}
%\usepackage[bottom, flushmargin]{footmisc}
\setlength{\footnotesep}{\baselineskip} % space between footnotes
\setlength{\parindent}{0pt} % space at start of paragraph
\setlength{\parskip}{0.14in} % space between paragraphs
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}

% colors
\usepackage[table]{xcolor} % more control over colors
\definecolor{c1}{HTML}{122084}
\usepackage{tcolorbox}

% heading formats
\usepackage[explicit]{titlesec}
\titlespacing\subsection{0pt}{0.21in}{0.01in}
\titlespacing\subsubsection{0pt}{0.21in}{0in}


% table-related
\usepackage{array}
\usepackage{booktabs}
\usepackage{multicol, makecell}
\usepackage{multirow, hhline}
\usepackage{siunitx}
\newcommand\bstrut{\rule{0pt}{2.5ex}} % space before row
\newcommand\astrut{\rule[-1.25ex]{0pt}{0pt}} % space after row
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\thispagestyle{plain}

\newcommand{\hsp}{\hspace{20pt}}
\titlespacing\section{0in}{0in}{0in}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries\filleft}{}{0pt}{\begin{tabular}[t]{r@{\hsp\color{c1}\vrule width 3pt}}#1\end{tabular}}

\section*{An Internationally \\ Renowned Title}

\vspace{0.5in}

\titlespacing\section{0cm}{0in}{0in}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{}{0pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt\hsp}l}#1\end{tabular}}

\section*{An Internationally \\ Renowned Title}

\end{document} 

enter image description here

7
  • Learned a lot more than I'd asked for from this - many thanks.
    – Thev
    Commented May 10, 2020 at 11:09
  • You're welcome. It's a pleasure to help!
    – Bernard
    Commented May 10, 2020 at 11:10
  • I don't suppose you know why there are two vertical rules on the right-hand side when you load showframe with geometry?
    – Thev
    Commented May 10, 2020 at 11:13
  • You're referring to the thin line at the margins? `showframe is done for that: make visible the layout of the page. For production, of course, remove this option.
    – Bernard
    Commented May 10, 2020 at 11:28
  • Oh, apologies - I did know that. I meant - why are there two lines on the right as opposed to one only on the left?
    – Thev
    Commented May 10, 2020 at 11:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .