页眉和页脚中的表格,页脚超出页面

页眉和页脚中的表格,页脚超出页面

我遇到了一些问题。页脚超出了页面范围,表格向左移动了一点。参见图片。

\documentclass[12pt]{article}
\newlength{\border}
\setlength{\border}{1cm}
\usepackage{geometry}
\geometry{left=2cm, right=2cm, top=\border, bottom=\border, includehead, includefoot}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{lastpage}
\usepackage{array}
\newcolumntype{x}{>{\centering\arraybackslash}X}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\usepackage{calc}
\usepackage{fancyhdr}
\fancypagestyle{mystyle}{%
    \newlength{\forheader}
    \setlength{\forheader}{(\paperwidth-2\border-\textwidth)}
    \fancyheadoffset{\forheader}
    \fancyfootoffset{\forheader}
    \newlength{\tabhead}
    \setlength{\tabhead}{(\textwidth+\forheader)}
    \fancyhf{}
    \fancyhead[C]{%
        \begin{tabularx}{\tabhead}{C{3.5cm}|x|C{5cm}}
            \multirow{3}{*}{\includegraphics[width=2cm]{example-image}} &
            \multirow{2}{*}{Text} &
            First
            \\ \cline{3-3}
            & & Second
            \\ \cline{3-3}
            & \multirow{-2}{*}{Latin report title} & Third
            \\ \hline
        \end{tabularx}
    }
    \fancyfoot[C]{%
        \begin{tabularx}{\tabhead}{C{4cm}|x|C{4cm}}
            \hline
            Page \thepage{} of \pageref{LastPage} &
            Text &
            Page \thepage{} of \pageref{LastPage}
        \end{tabularx}
    }
    \renewcommand{\headrulewidth}{0pt}
}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{eso-pic}
\usepackage{lipsum}
\AddToShipoutPictureBG{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[line width=1pt]
        ($ (current page.north west) + (\border,-\border) $)
        rectangle
        ($ (current page.south east) + (-\border,\border) $);
    \end{tikzpicture}
}
\pagestyle{mystyle}
\headheight43.9pt
\begin{document}
    \lipsum
    
    \lipsum
\end{document} 

在此处输入图片描述


页脚必须像页眉一样。在边框中!

在此处输入图片描述

答案1

\documentclass[12pt]{article}
\newlength{\border}
\setlength{\border}{1cm}
\newlength{\margins}
\setlength{\margins}{\dimexpr\border+1cm}
\usepackage{geometry}
\geometry{left=\margins, right=\margins, top=\border, bottom=\border, includehead, includefoot}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{lastpage}
\usepackage{array}
\newcolumntype{x}{>{\centering\arraybackslash}X}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\usepackage{fancyhdr}
\fancypagestyle{mystyle}{%
    \newlength{\forheader}
    \setlength{\forheader}{\dimexpr\paperwidth-2\border-\textwidth}
    \fancyheadoffset{\forheader}
    \fancyfootoffset{\forheader}
    \newlength{\tabhead}
    \setlength{\tabhead}{\dimexpr\textwidth+\forheader}
    \fancyhf{}
    \fancyhead[C]{%
        \begin{tabularx}{\tabhead}{C{3.5cm}|x|C{4cm}}
            \multirow{3}{*}{\includegraphics[width=2cm]{example-image}} &
            \multirow{2}{*}{Text} &
            First 
            \tabularnewline \cline{3-3}
            & & Second 
            \tabularnewline \cline{3-3}
            & \multirow{-2}{*}{Latin report title} & Third 
            \tabularnewline \hline
        \end{tabularx}%
    }
    \fancyfoot[C]{%
        \raisebox{\depth}{%
            \begin{tabularx}{\tabhead}{C{4cm}|x|C{4cm}}
                \hline
                Page \thepage{} of \pageref{LastPage} &
                Text &
                Page \thepage{} of \pageref{LastPage}
            \end{tabularx}%
        }%
    }
    \renewcommand{\headrulewidth}{0pt}
}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{eso-pic}
\usepackage{lipsum}
\AddToShipoutPictureBG{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[line width=1pt]
        ($ (current page.north west) + (\border,-\border) $)
        rectangle
        ($ (current page.south east) + (-\border,\border) $);
    \end{tikzpicture}
}
\pagestyle{mystyle}
\headheight43.9pt
\setlength{\textheight}{\dimexpr\paperheight-\headheight-\headsep-\footskip-2\border}
\begin{document}
    \lipsum
    
    \lipsum
\end{document}

相关内容