![如何在横向页面(tikz)latex中绘制矩形框](https://linux22.com/image/448074/%E5%A6%82%E4%BD%95%E5%9C%A8%E6%A8%AA%E5%90%91%E9%A1%B5%E9%9D%A2%EF%BC%88tikz%EF%BC%89latex%E4%B8%AD%E7%BB%98%E5%88%B6%E7%9F%A9%E5%BD%A2%E6%A1%86.png)
我在同一个 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}