我怎样才能使用 pstricks 或 tikz 轻松地做到这一点,我无法将文本放在正确的位置
我的 MWE
\documentclass[a4paper]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage[x11names]{xcolor}
\usepackage{fancyhdr}
\usepackage{pstricks,pstricks-add,graphicx}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\baselinestretch}{1.3}
\setlength{\parindent}{0cm}
\psset{linecolor=red}
\begin{document}
\psframe(-0.2,1.1)(1.007\textwidth ,-\textheight)
\psline{}(-0.2,-2)(1.007\textwidth ,-2)
\psline{}(0.5\textwidth ,1.1)(0.5\textwidth ,-2)
\begin{minipage}[t]{0.48\textwidth}
\end{minipage}
\hfill
\begin{minipage}[t]{0.48\textwidth}
\end{minipage}
\psline{}(-0.2,0)(1.007\textwidth ,0)
\psline{}(-0.2,-1)(1.007\textwidth ,-1)
\psline{}(0.65\textwidth ,0)(0.65\textwidth ,-21.3)
%===================================================
\begin{minipage}[t]{0.64\textwidth}
\end{minipage}
%===================================================
\hfill
%===================================================
\begin{minipage}[t]{0.3\textwidth}
\end{minipage}
%===================================================
\end{document}
答案1
这是一个 tikz 解决方案。首先考虑结果:
网格中的线条是在预先定义的坐标之间绘制的,以提供灵活性。例如,文本“中间部分”下方的水平线位于表格高度的 20%,分隔“底部左侧”和“底部右侧”的垂直线位于表格宽度的 33%。
但是,“中间部分”上方的线不是表格的百分比,而是以这样一种方式定义的,即“顶部”和“中间部分”单元格具有相同的高度。“左标题”和“右标题”下方的线固定为 1cm 高度。
文本放置在每个单元格的中间,但它应该是“短文本”。否则,您必须给它一个 text width
键,以使段落正确格式化。
以下是代码:
\documentclass[a4paper]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]\Large
% Coordinates of the external frame
\coordinate (top) at ($(current page.north)+(0,-1.5)$);
\coordinate (bottom) at ($(current page.south)+(0,1.5)$);
\coordinate (left) at ($(current page.west)+(1.5,0)$);
\coordinate (right) at ($(current page.east)+(-1.5,0)$);
% Coordinates of the horizontal parts
\coordinate (middle part) at ($(top)!.20!(bottom)$);
\coordinate (top part) at ($(top)!.5!(middle part)$);
\coordinate (bottom part header) at ($(middle part)+(0,-1)$);
\coordinate (left part) at ($(left)!.33!(right)$);
\coordinate (half part) at ($(left)!.50!(right)$);
% Frame around
\draw[red] (bottom-|left) rectangle (top-|right);
% Horizontal lines
\draw[red] (top part-|left) -- (top part-|right);
\draw[red] (middle part-|left) -- (middle part-|right);
\draw[red] (bottom part header-|left) -- (bottom part header-|right);
% Vertical lines
\draw[red] (top-|half part) -- (top part-|half part);
\draw[red] (middle part-|left part) -- (bottom-|left part);
\node at ($(top-|left)!.5!(top part-|half part)$) {Top part middle left};
\node at ($(top-|right)!.5!(top part-|half part)$) {Top part middle right};
\node at ($(top part-|half part)!.5!(middle part-|half part)$) {Middle part};
\node at ($(middle part-|left)!.5!(bottom part header-|left part)$) {Left header};
\node at ($(middle part-|right)!.5!(bottom part header-|left part)$) {Right header};
\node at ($(bottom part header-|left)!.5!(bottom-|left part)$) {Bottom part left};
\node at ($(bottom part header-|right)!.5!(bottom-|left part)$) {Bottom part right};
\end{tikzpicture}
\end{document}