如何控制 tikzpicture 的边距

如何控制 tikzpicture 的边距

我有以下代码来绘制标题页的边框。我想在左侧和右侧设置边框的边距。如何设置左侧边距为 1.5 英寸,右侧边距为 1 英寸。

\documentclass[12pt, a4, openany, oneside]{book}
\renewcommand{\baselinestretch}{1.6}
\usepackage[left=1.5in,top=1.0in,right=1.0in,bottom=1.0in]{geometry}
%\setlrmarginsandblock{2.5cm}{2.5cm}{*} % Left and right margin
%\setulmarginsandblock{3cm}{3cm}{*}  % Upper and lower margin
%\checkandfixthelayout

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
            {-2.5ex\@plus -1ex \@minus -.25ex}%
            {1.25ex \@plus .25ex}%
            {\normalfont\normalsize\bfseries}}

\renewcommand\subparagraph{%
 \@startsection {subparagraph}{5}{\z@ }{2.25ex \@plus 1ex
 \@minus .2ex}{-1em}{\normalfont \normalsize \bfseries }}%


\usepackage{enumitem}
\setlistdepth{9} % deep listing to 6th level (9- 6(by default))
\newlist{myenumerate}{enumerate}{9} % deep listing
\setlist[myenumerate]{label*=\arabic*.}
\setlist[enumerate]{label*=\arabic*.} % for default level


%margin
%\usepackage[top=1in, bottom=1in, left=1.25in, right=1.25in]{geometry}


\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[english]{babel}



\begin{document}


%paragraph spacing
%\setlength{\parskip}{\baselineskip}%

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\begin{titlepage}

   \begin{tikzpicture}[remember picture,overlay,inner sep=0.5,outer sep=0]
     \draw[blue!70!black,line width=4pt] ([xshift=-1.5cm,yshift=-2cm]current page.north east) coordinate (A)--([xshift=1.5cm,yshift=-2cm]current page.north west) coordinate(B)--([xshift=1.5cm,yshift=2cm]current page.south west) coordinate (C)--([xshift=-1.5cm,yshift=2cm]current page.south east) coordinate(D)--cycle;

     \draw ([yshift=0.5cm,xshift=-0.5cm]A)-- ([yshift=0.5cm,xshift=0.5cm]B)--
     ([yshift=-0.5cm,xshift=0.5cm]B) --([yshift=-0.5cm,xshift=-0.5cm]B)--([yshift=0.5cm,xshift=-0.5cm]C)--([yshift=0.5cm,xshift=0.5cm]C)--([yshift=-0.5cm,xshift=0.5cm]C)-- ([yshift=-0.5cm,xshift=-0.5cm]D)--([yshift=0.5cm,xshift=-0.5cm]D)--([yshift=0.5cm,xshift=0.5cm]D)--([yshift=-0.5cm,xshift=0.5cm]A)--([yshift=-0.5cm,xshift=-0.5cm]A)--([yshift=0.5cm,xshift=-0.5cm]A);


     \draw ([yshift=-0.3cm,xshift=0.3cm]A)-- ([yshift=-0.3cm,xshift=-0.3cm]B)--
     ([yshift=0.3cm,xshift=-0.3cm]B) --([yshift=0.3cm,xshift=0.3cm]B)--([yshift=-0.3cm,xshift=0.3cm]C)--([yshift=-0.3cm,xshift=-0.3cm]C)--([yshift=0.3cm,xshift=-0.3cm]C)-- ([yshift=0.3cm,xshift=0.3cm]D)--([yshift=-0.3cm,xshift=0.3cm]D)--([yshift=-0.3cm,xshift=-0.3cm]D)--([yshift=0.3cm,xshift=-0.3cm]A)--([yshift=0.3cm,xshift=0.3cm]A)--([yshift=-0.3cm,xshift=0.3cm]A);

   \end{tikzpicture}


\begin{center}





  \vspace{.3cm}
  \textbf{\large{\uppercase{This is the title of the thesis}}}

\end{center}
\end{titlepage}
\end{document} 

在此处输入图片描述

答案1

好消息是,所有内容都是相对于坐标 (A) (B) (C) 和 (D) 绘制的。坏消息是,这些不是内部边缘。那些(注意角落)在 0.5 厘米处。

\documentclass[12pt, a4, openany, oneside]{book}
\renewcommand{\baselinestretch}{1.6}
\usepackage[left=1.5in,top=1.0in,right=1.0in,bottom=1.0in]{geometry}
%\setlrmarginsandblock{2.5cm}{2.5cm}{*} % Left and right margin
%\setulmarginsandblock{3cm}{3cm}{*}  % Upper and lower margin
%\checkandfixthelayout

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
            {-2.5ex\@plus -1ex \@minus -.25ex}%
            {1.25ex \@plus .25ex}%
            {\normalfont\normalsize\bfseries}}

\renewcommand\subparagraph{%
 \@startsection {subparagraph}{5}{\z@ }{2.25ex \@plus 1ex
 \@minus .2ex}{-1em}{\normalfont \normalsize \bfseries }}%


\usepackage{enumitem}
\setlistdepth{9} % deep listing to 6th level (9- 6(by default))
\newlist{myenumerate}{enumerate}{9} % deep listing
\setlist[myenumerate]{label*=\arabic*.}
\setlist[enumerate]{label*=\arabic*.} % for default level


%margin
%\usepackage[top=1in, bottom=1in, left=1.25in, right=1.25in]{geometry}


\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[english]{babel}



\begin{document}


%paragraph spacing
%\setlength{\parskip}{\baselineskip}%

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\begin{titlepage}

   \begin{tikzpicture}[remember picture,overlay,inner sep=0.5,outer sep=0]
     \path (current page.north east) ++(-1in+0.5cm,-1in+0.5cm) coordinate (A)
           (current page.north west) ++(1.5in-0.5cm,-1in+0.5cm) coordinate (B)
           (current page.south west) ++(1.5in-0.5cm,1in-0.5cm) coordinate (C)
           (current page.south east) ++(-1in+0.5cm,1in-0.5cm) coordinate (D);
     \draw[blue!70!black,line width=4pt] (A)--(B)--(C)--(D)--cycle;

     \draw ([yshift=0.5cm,xshift=-0.5cm]A)-- ([yshift=0.5cm,xshift=0.5cm]B)--
     ([yshift=-0.5cm,xshift=0.5cm]B) --([yshift=-0.5cm,xshift=-0.5cm]B)--([yshift=0.5cm,xshift=-0.5cm]C)--([yshift=0.5cm,xshift=0.5cm]C)--([yshift=-0.5cm,xshift=0.5cm]C)-- ([yshift=-0.5cm,xshift=-0.5cm]D)--([yshift=0.5cm,xshift=-0.5cm]D)--([yshift=0.5cm,xshift=0.5cm]D)--([yshift=-0.5cm,xshift=0.5cm]A)--([yshift=-0.5cm,xshift=-0.5cm]A)--([yshift=0.5cm,xshift=-0.5cm]A);


     \draw ([yshift=-0.3cm,xshift=0.3cm]A)-- ([yshift=-0.3cm,xshift=-0.3cm]B)--
     ([yshift=0.3cm,xshift=-0.3cm]B) --([yshift=0.3cm,xshift=0.3cm]B)--([yshift=-0.3cm,xshift=0.3cm]C)--([yshift=-0.3cm,xshift=-0.3cm]C)--([yshift=0.3cm,xshift=-0.3cm]C)-- ([yshift=0.3cm,xshift=0.3cm]D)--([yshift=-0.3cm,xshift=0.3cm]D)--([yshift=-0.3cm,xshift=-0.3cm]D)--([yshift=0.3cm,xshift=-0.3cm]A)--([yshift=0.3cm,xshift=0.3cm]A)--([yshift=-0.3cm,xshift=0.3cm]A);

   \end{tikzpicture}


\begin{center}





  \vspace{.3cm}
  \textbf{\large{\uppercase{This is the title of the thesis}}}

\end{center}
\end{titlepage}
\end{document}

此解决方案适用于任何文本区域。只是为了好玩,我删除了所有[yshift=...,xshift=...]符号,而改用 calc 符号。

\documentclass[12pt, a4, openany, oneside]{book}
\renewcommand{\baselinestretch}{1.6}
\usepackage[left=1.5in,top=1.0in,right=1.0in,bottom=1.0in]{geometry}
%\setlrmarginsandblock{2.5cm}{2.5cm}{*} % Left and right margin
%\setulmarginsandblock{3cm}{3cm}{*}  % Upper and lower margin
%\checkandfixthelayout

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
            {-2.5ex\@plus -1ex \@minus -.25ex}%
            {1.25ex \@plus .25ex}%
            {\normalfont\normalsize\bfseries}}

\renewcommand\subparagraph{%
 \@startsection {subparagraph}{5}{\z@ }{2.25ex \@plus 1ex
 \@minus .2ex}{-1em}{\normalfont \normalsize \bfseries }}%


\usepackage{enumitem}
\setlistdepth{9} % deep listing to 6th level (9- 6(by default))
\newlist{myenumerate}{enumerate}{9} % deep listing
\setlist[myenumerate]{label*=\arabic*.}
\setlist[enumerate]{label*=\arabic*.} % for default level


%margin
%\usepackage[top=1in, bottom=1in, left=1.25in, right=1.25in]{geometry}


\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage[english]{babel}

\begin{document}

%paragraph spacing
%\setlength{\parskip}{\baselineskip}%

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\begin{titlepage}

  \begin{tikzpicture}[remember picture,overlay]
    \path (current page text area.north east) ++(0.5cm,0.5cm) coordinate (A)
          (current page text area.north west) ++(-0.5cm,0.5cm) coordinate (B)
          (current page text area.south west) ++(-0.5cm,-0.5cm) coordinate (C)
          (current page text area.south east) ++(0.5cm,-0.5cm) coordinate (D);
    \draw[blue!70!black,line width=4pt] (A)--(B)--(C)--(D)--cycle;

    \draw ($(A)+(-0.5cm,0.5cm)$)--($(B)+(0.5cm,0.5cm)$)--($(B)+(0.5cm,-0.5cm)$)--($(B)+(-0.5cm,-0.5cm)$)--
          ($(C)+(-0.5cm,0.5cm)$)--($(C)+(0.5cm,0.5cm)$)--($(C)+(0.5cm,-0.5cm)$)--($(D)+(-0.5cm,-0.5cm)$)--
          ($(D)+(-0.5cm,0.5cm)$)--($(D)+(0.5cm,0.5cm)$)--($(A)+(0.5cm,-0.5cm)$)--($(A)+(-0.5cm,-0.5cm)$)--cycle;

    \draw ($(A)+(0.3cm,-0.3cm)$)--($(B)+(-0.3cm,-0.3cm)$)--($(B)+(-0.3cm,0.3cm)$)--($(B)+(0.3cm,0.3cm)$)--
          ($(C)+(0.3cm,-0.3cm)$)--($(C)+(-0.3cm,-0.3cm)$)--($(C)+(-0.3cm,0.3cm)$)--($(D)+(0.3cm,0.3cm)$)--
          ($(D)+(0.3cm,-0.3cm)$)--($(D)+(-0.3cm,-0.3cm)$)--($(A)+(-0.3cm,0.3cm)$)--($(A)+(0.3cm,0.3cm)$)--cycle;
\end{tikzpicture}


\begin{center}

  \vspace{.3cm}
  \textbf{\large{\uppercase{This is the title of the thesis}}}

\end{center}
\end{titlepage}
\end{document} 

相关内容