在 tikzpicture 中使用 \textwidth 建立居中映像

在 tikzpicture 中使用 \textwidth 建立居中映像

我想在 A4 頁面的中央放置一張橫向模式的 tikzpicture。但是,我無法使用\textwidth\textheight命令,因為這將導致overfull \hbox...overfull \vbox...錯誤以及空白的首頁。我認為某處有一些微小的邊距或縮排?

我看過一個夫妻執行緒在這裡,但到目前為止沒有任何效果。微量元素:

\documentclass[a4paper,landscape]{minimal}

\usepackage[margin=1cm]{geometry}
\usepackage{tikz}

\begin{document}
\begin{center}
\begin{tikzpicture}
  \draw (0, 0) rectangle (0.999\textwidth,0.999\textheight);

  % this will give "overfull \hbox..." or "overfull \vbox..." errors
  % and create an empty first page
  % \draw (0, 0) rectangle (\textwidth,\textheight);
\end{tikzpicture}
\end{center}
\end{document}

在此輸入影像描述

謝謝你!

答案1

歡迎!您需要考慮線寬。 (我按照分形的建議切換到文章。)在每一端,邊界框都會增加\pgflinewidth/2,因此您需要對此進行修正。

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}

\begin{document}
%\begin{center} %<- not needed
\noindent\begin{tikzpicture}
  \draw (0, 0) rectangle (\textwidth-\pgflinewidth,\textheight-\pgflinewidth);
\end{tikzpicture}
%\end{center}
\end{document}

相關內容