Apply hrule at bottom of each page’s text body

double-sidedheader-footerlayoutrulestextwidth

I am working on a twosided article layout where the footnotes are enclosed by two \textwidth lines above and below and on pages without a footnote a single h-line is spanning across \textwidth at the bottom of the text-body. But the footer itself should span across \textwidth plus \marginparwidth

I tried the fancyhdr to create a line at the border between footer and text-body, but on even pages the footrule hangs on the wrong side:

footrule hanging on wrong side on even pages

It should look like on odd pages:

enter image description here

Here is a MWE:

\documentclass[a4paper,12pt,
twoside,%
]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{%
    inner=2cm,
    outer=4cm,
    top=2.5cm,
    bottom=2.5cm,
    marginparwidth=3cm,
}
\setlength\parindent{0pt}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyfoot[EL,OR]{\textbf{\thepage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.5pt}
\addtolength{\headwidth}{\marginparwidth}
\renewcommand\footrule{\hrule width\textwidth}
\fancypagestyle{plain}{}

\usepackage[%
hang,%
%marginal,%
bottom%
]{footmisc}
\setlength{\footnotemargin}{0.5cm} %Abstand zwischen textkörper und FN bei hang-option
%\setlength{\footnotesep}{0.35cm} %Abstand zwischen FN
\setlength{\skip\footins}{0,5cm} %Abstand zwischen FN-Nummer und FN-Text
\renewcommand{\footnoterule}{\rule{\textwidth}{0.5pt}{\vspace*{2mm}}}

\usepackage{blindtext}

\begin{document}
    \blindtext[3]\footnote{text}
    \blindtext[3]\footnote{text}
    \blindtext[4]
\end{document}

The important part oft the layout is the horizontal rule at the bottom of the text-body, on pages with and without footnotes.

I guess some more professional TeX-users can offer a solution.

Edit:

If someone has another solution without fancyhdr, I'm also happy. As long as it looks like the second picture and offers a footer spanning through textwidth and marginparwidth (where the pagenumber is displayed).

2. Edit:

Unfortunatley, the test pages which i got to style the Latex layout had footnotes on every page. But the layout expects a single hrule at the bottom of the text-body also on pages without a footnote. Therefore, @cabohah's great solution doesn't fit my needs, because the lower rule only appears if a footnote-command is called. Sorry for the confusion. Is there a possibility to place a hrule on the bottom of the text-body of every page, notwithstanding if there is a footnote or not? Also updated the initial question above with this requirement.

Thanks and best!

Best Answer

Instead of trying to add the rule below the footnotes to the page footer, you could patch the output of the footnotes:

\documentclass[a4paper,12pt,twoside,]{article}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% not needed with LaTeX 2018/04/01 or newer

\usepackage{geometry}
\geometry{%
    inner=2cm,
    outer=4cm,
    top=2.5cm,
    bottom=2.5cm,
    marginparwidth=3cm,
}
\usepackage{parskip}

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyfoot[EL,OR]{\textbf{\thepage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headwidth}{\marginparwidth}
\fancypagestyle{plain}{}

\usepackage[hang,bottom]{footmisc}
\setlength{\footnotemargin}{0.5cm} %Abstand zwischen textkörper und FN bei hang-option
%\setlength{\footnotesep}{0.35cm} %Abstand zwischen FN
\setlength{\skip\footins}{0,5cm} %Abstand zwischen FN-Nummer und FN-Text

\makeatletter
\renewcommand\footnoterule{\kern-3\p@
  \hrule \@width \textwidth \kern 2.6\p@} % the \hrule is .4pt high and now it has the width of the text area
\makeatother

\usepackage{xpatch}
% NOTE: The following code depends on usage of package footmisc!
\makeatletter
\xpatchcmd{\@outputbox@appendfootnotes}{%
  \unvbox \footins
}{%
  \unvbox \footins
  \secondfootnoterule
}{}{\PAtchFailure}
\newcommand*{\secondfootnoterule}{\hrule \@width \textwidth \kern -0.4\p@}
\makeatother

\usepackage{blindtext}

\begin{document}
    \blindtext[3]\footnote{text}
    \blindtext[3]\footnote{text}
    \blindtext[4]
\end{document}

enter image description here

Here a similar solution, for those who do not use footmisc:

\documentclass[a4paper,12pt,twoside,]{article}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% not needed with LaTeX 2018/04/01 or newer

\usepackage{geometry}
\geometry{%
    inner=2cm,
    outer=4cm,
    top=2.5cm,
    bottom=2.5cm,
    marginparwidth=3cm,
}
\usepackage{parskip}

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyfoot[EL,OR]{\textbf{\thepage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headwidth}{\marginparwidth}
\fancypagestyle{plain}{}

\usepackage{xpatch}
% NOTE: The following code depends on NOT using package footmisc!
\makeatletter
\xpatchcmd{\@makecol}{%
  \unvbox \footins
}{%
  \unvbox \footins
  \secondfootnoterule
}{}{\PAtchFailure}
\renewcommand\footnoterule{\kern-3\p@\hrule \@width \textwidth \kern 2.6\p@} % the \hrule is .4pt high and has the width of the text area
\newcommand*{\secondfootnoterule}{\hrule \@width \textwidth \kern -0.4\p@}
\makeatother

\usepackage{blindtext}

\begin{document}
    \blindtext[3]\footnote{text}
    \blindtext[3]\footnote{text}
    \blindtext[4]
\end{document}

enter image description here


EDIT because of change of question to a completely different one

If you are just asking for a separation line above the page footer, that should only span the width of the text area, despite the page number should be aligned at the outer edge of the \marginpar column, the simplest solution would be to use package scrlayer-scrpage. It provides not only to set the line length independent from the footer width, but also to align all separation lines either centered, inner aligned or outer aligned. So

\documentclass[a4paper,12pt,twoside]{article}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% not needed with LaTeX 2018/04/01 or newer

\usepackage{geometry}
\geometry{%
    inner=2cm,
    outer=4cm,
    top=2.5cm,
    bottom=2.5cm,
    marginparwidth=3cm,
}
\usepackage{parskip}

\usepackage[footwidth=textwithmarginpar,footsepline=0.4pt:text,ilines]{scrlayer-scrpage}
\clearpairofpagestyles
\ofoot*{\pagemark}

\usepackage{blindtext}

\begin{document}
\blinddocument
\end{document}

Is enough to get:

using scrlayer-scrpage

If you want a bold page number, you can use \addtokomafont{pagefoot}{\bfseries}.

If you cannot use scrlayer-scrpage for some reason, not expanding the \headwidth but move the pagination into the outer margin would be a suggestion without redefining \footrule:

\documentclass[a4paper,12pt,twoside,]{article}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% not needed with LaTeX 2018/04/01 or newer

\usepackage{geometry}
\geometry{%
    inner=2cm,
    outer=4cm,
    top=2.5cm,
    bottom=2.5cm,
    marginparwidth=3cm,
}
\usepackage{parskip}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[EL]{\makebox[0pt][r]{\makebox[\dimexpr\marginparwidth+\marginparsep\relax][l]{\textbf{\thepage}}}}
\fancyfoot[OR]{\makebox[0pt][l]{\makebox[\dimexpr\marginparwidth+\marginparsep\relax][r]{\textbf{\thepage}}}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}
\fancypagestyle{plain}{}

\usepackage{blindtext}

\begin{document}
\Blinddocument
\end{document}

using fancyhdr

Related Question