我在同一个 latex 文件上有两页文档,一个是纵向的,一个是横向的。我需要为这两页绘制一个矩形框,左边距为 3cm,右边距为 2cm,上边距为 2cm,下边距为 2cm。对于纵向页面,我使用与下面相同的代码,但横向页面无法正确绘制。我认为坐标发生了变化。
\documentclass{article}
\usepackage{tikz}
\usepackage{pdflscape}
\usetikzlibrary{calc}
\usepackage[fontsize=14pt]{scrextend}%font mặc định
\usepackage[paperheight=21cm,paperwidth=29.7cm,right=2.6cm,left=3.5cm,top=2cm,bottom=2cm]{geometry}%font a4
\begin{document}
\begin{tikzpicture}[overlay,remember picture]
\draw [line width=3pt]
($ (current page.north west)+ (3.0cm,-2.0cm) $)
rectangle
($ (current page.south east) + (-2.0cm, 2.5cm) $);
\draw [line width=0.5pt]
($ (current page.north west) + (3.1cm,-2.1cm) $)
rectangle
($ (current page.south east) + (-2.1cm,2.6cm) $);
\end{tikzpicture}
\newpage
\begin{landscape}
\begin{tikzpicture}[overlay,remember picture]
\draw [line width=3pt]
($ (current page.north west)+ (3.0cm,-2.0cm) $)
rectangle
($ (current page.south east) + (-2.0cm, 2.5cm) $);
\draw [line width=0.5pt]
($ (current page.north west) + (3.1cm,-2.1cm) $)
rectangle
($ (current page.south east) + (-2.1cm,2.6cm) $);
\end{tikzpicture}
\end{landscape}
\end{document}
答案1
该pdflscape
包在横向坐标方面存在问题,但该typearea
包工作正常。请注意切换方向时必须添加的两行:
\KOMAoptions{paper=portrait,pagesize}
\recalctypearea
\documentclass{article}
\usepackage{tikz}
%\usepackage{pdflscape}
\usepackage[paper=portrait,pagesize]{typearea}
\usetikzlibrary{calc}
\usepackage[fontsize=14pt]{scrextend}%font mặc định
\usepackage[paperheight=21cm,paperwidth=29.7cm,right=2.6cm,left=3.5cm,top=2cm,bottom=2cm]{geometry}%font a4
\begin{document}
\begin{tikzpicture}[overlay,remember picture]
\draw [line width=3pt]
($ (current page.north west)+ (3.0cm,-2.0cm) $)
rectangle
($ (current page.south east) + (-2.0cm, 2.5cm) $);
\draw [line width=0.5pt]
($ (current page.north west) + (3.1cm,-2.1cm) $)
rectangle
($ (current page.south east) + (-2.1cm,2.6cm) $);
\end{tikzpicture}
\newpage
\KOMAoptions{paper=portrait,pagesize}
\recalctypearea
\begin{tikzpicture}[overlay,remember picture]
\draw [line width=3pt]
($ (current page.north west)+ (3.0cm,-2.0cm) $)
rectangle
($ (current page.south east) + (-2.0cm, 2.5cm) $);
\draw [line width=0.5pt]
($ (current page.north west) + (3.1cm,-2.1cm) $)
rectangle
($ (current page.south east) + (-2.1cm,2.6cm) $);
\end{tikzpicture}
\end{document}