简体   繁体   中英

Raggedleft in minipage in a footer designed using fancyhdr

the goal is to design a two-sided report. In the footer of the left pages shall be the page number at the outer edge ( right-justified ), then a vertical line, and then the chapter name (left-justified). On the right pages shall be the section name (right-justified), a vertical line, and finally the page number (left-justified). The right page design works with all alignments, whereas on the left page, the alignment of the page number fails, ie the bold-written setting does not work.

Here is how I coded this:

\documentclass[a4paper,twoside,openright]{report}

\usepackage[top=2cm,bottom=4cm,inner=3cm,outer=2cm,footskip=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage{blindtext}

\def\vfootline{\begingroup\rule[-990pt]{0.5pt}{1000pt}\endgroup}
\fancyfootoffset{15.5pt}
\renewcommand\headrulewidth{0pt}
\fancypagestyle{dummy}{
    \fancyhead{}
    \fancyfoot{}
    \fancyfoot[LE]{
        \begin{minipage}[b]{0cm}
            \raggedleft\thepage
        \end{minipage}
        \hspace*{10pt}
        \vfootline
        \hspace*{10pt}
        \leftmark
    }
    \fancyfoot[RO]{
        \roboto
        \rightmark
        \hspace*{10pt}
        \vfootline
        \hspace*{10pt}
        \begin{minipage}[b]{0cm}
            \raggedright\thepage
        \end{minipage}
    }
}

% document
\begin{document}

\pagenumbering{roman}
\pagestyle{dummy}

\Blinddocument

\end{document}

I chose roman numbers, as they show the problem better. Please have a look at the alignment:

左页页码对齐错误的页脚

Appreciate every hint or solution. Thanks in advance!

Best, Toni

Your left/right alignment of the text inside the minipages will only make sense if they are wide enough to accommodate the content.

\documentclass[a4paper,twoside,openright]{report}

\usepackage[top=2cm,bottom=4cm,inner=3cm,outer=2cm,footskip=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage{blindtext}

\def\vfootline{\begingroup\rule[-990pt]{0.5pt}{1000pt}\endgroup}
\fancyfootoffset{15.5pt}
\renewcommand\headrulewidth{0pt}
\fancypagestyle{dummy}{
    \fancyhead{}
    \fancyfoot{}
    \fancyfootoffset[OR]{1.85cm}%
    \fancyfoot[OR]{%
        {\ }% 
%       \roboto%
        {%
            \rightmark%
        }%
        \hspace*{10pt}
        {%
            \rule[-90pt]{1.25pt}{100pt}%
        }%
        \hspace*{10pt}%
        \begin{minipage}[b]{1.5cm}%
            \thepage%
        \end{minipage}%
    }
    \fancyfootoffset[EL]{1.85cm}%
    \fancyfoot[EL]{%
%       \roboto
        \begin{minipage}[b]{1.5cm}%
            \raggedleft%
            \thepage%
        \end{minipage}%
        \hspace*{10pt}%
        {%
            \rule[-90pt]{1.25pt}{100pt}%
        }%
        \hspace*{10pt}%
        {%
            \leftmark%
        }%
    }%
}




% document
\begin{document}

\pagenumbering{roman}
\pagestyle{dummy}

\Blinddocument

\end{document}

在此处输入图像描述

Alternatively you could use \makebox instead of minipages:

\documentclass[a4paper,twoside,openright]{report}

\usepackage[top=2cm,bottom=4cm,inner=3cm,outer=2cm,footskip=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage{blindtext}

\def\vfootline{\begingroup\rule[-990pt]{0.5pt}{1000pt}\endgroup}
\fancyfootoffset{15.5pt}
\renewcommand\headrulewidth{0pt}
\fancypagestyle{dummy}{
    \fancyhead{}
    \fancyfoot{}
    \fancyfoot[LE]{
        \makebox[0pt][r]{\thepage}
        \hspace*{10pt}
        \vfootline
        \hspace*{10pt}
        \leftmark
    }
    \fancyfoot[RO]{
%        \roboto
        \rightmark
        \hspace*{10pt}
        \vfootline
        \hspace*{10pt}
        \makebox[0pt][l]{\thepage}
    }
}

% document
\begin{document}

\pagenumbering{roman}
\pagestyle{dummy}

\Blinddocument

\end{document}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM