3

I have two document pages, one portrait, one landscape, on the same latex file. I need to draw a rectangular frame with 3cm left margin, 2cm right margin, 2cm top margin, 2cm bottom margin for both pages. For portrait page, I use the same code as below but the landscape page can't be drawn properly. I think that the co-ordinate is changed.

\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

1 Answer 1

6

The pdflscape package has trouble with coordinates in landscape, but the typearea package works fine. Note the two lines that must be added when you switch orientation:

\KOMAoptions{paper=portrait,pagesize}
\recalctypearea

See these two answers for more information.

enter image description here

\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}
2
  • But how can I change the margin back to [right=2.6cm,left=3.5cm,top=2cm,bottom=2cm] with KOMAoption?
    – tungsondkh
    Commented Apr 5, 2022 at 15:16
  • @tungsondkh: Does this help?
    – Sandy G
    Commented Apr 6, 2022 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .