如何用 tikz 使单边变圆?

如何用 tikz 使单边变圆?

我不擅长使用 tikz。我知道这个问题已经得到了一般性的回答(例如,这里),但我无法将其转移到我的示例。我有以下代码:

\documentclass[a4paper]{article}

\usepackage{geometry}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{background}

\usetikzlibrary{calc}
\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{black}
\SetBgContents{
\begin{tikzpicture}[overlay,remember picture]
    \draw [line width=1pt,rounded corners=17pt,
        ]
        ($ (current page.north west) + (1.2cm,-1cm) $)
        rectangle
        ($ (current page.south east) + (-1cm,2cm) $);
\end{tikzpicture}
}

\begin{document}
\lipsum
\end{document}

这会在整个页面周围产生这种类型的矩形:

在此处输入图片描述

我怎样才能使西北角和东南角不圆?所以我的特殊限制是我希望矩形围绕整个文本,相对于页面大小。

答案1

只需画两条不同的线:

  • 一条从西北到东西再到东南角
  • 另一条从西北到西南再到东南角

使用该rounded corners选项,只有中间角会变圆:

在此处输入图片描述

完整代码如下:

\documentclass[a4paper]{article}

\usepackage{geometry}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{background}

\usetikzlibrary{calc}
\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{black}
\SetBgContents{
  \begin{tikzpicture}[overlay,remember picture]
      \draw [line width=1pt,rounded corners=17pt]
             ($ (current page.north west) + (12mm,-12mm) $)
          -- ($ (current page.north east) + (-12mm,-12mm) $)
          -- ($ (current page.south east) + (-12mm,12mm) $);
      \draw [line width=1pt,rounded corners=17pt]
             ($ (current page.north west) + (12mm,-12mm) $)
          -- ($ (current page.south west) + (12mm,12mm) $)
          -- ($ (current page.south east) + (-12mm,12mm) $);
  \end{tikzpicture}
}

\begin{document}
\lipsum
\end{document}

编辑

正如 Zarko 在评论中所说,更好的解决方案是使用:

\SetBgContents{
  \begin{tikzpicture}[overlay,remember picture]
      \draw [line width=1pt,rounded corners=17pt, ]
        ($ (current page.north west) + (12mm,-12mm) $)
          -| ($ (current page.south east) + (-12mm,12mm) $)
             ($ (current page.south east) + (-12mm,12mm) $)
          -| ($ (current page.north west) + (12mm,-12mm) $);
  \end{tikzpicture}
}

相关内容