我重新绘制了一张用 tikz 在网上找到的图形样本,作为测试。现在它变得有点复杂,我对不同的可能解决方案感兴趣。也许文字少一些,也许有其他特色。
这是 MWE:
\documentclass{article}
%Font settings
\usepackage[default]{sourcesanspro}
%Support for German
\usepackage[utf8]{inputenc}
\usepackage[greek,ngerman]{babel}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[xscale=0.8, yscale=0.8,]
%( left lower edge ) rectangle (right top edge) node[anchor=center] at (x,y in rectangle)
\filldraw[ fill=green!20, align=center, thick, rounded corners=2pt,]
(-1.8,2.9) rectangle (5.1,1.7) node[anchor=center] at (1.7,2.25)
{ <header> \\ \footnotesize contains the brandings like logo };
\filldraw[fill=green!20, align=center, thick, rounded corners=2pt,]
(-1.8,0.3) rectangle (5.1,1.55) node[anchor=center] at (1.7,0.9)
{ <nav> \\ \footnotesize contains navigational section of the site };
\filldraw[fill=green!20, align=center, thick, rounded corners=2pt,]
(-1.8,-3.1) rectangle (2.2,0.2) node[anchor=center] at (0.2,-0.5)
{\footnotesize <article> \\ \tiny web page main content };
\filldraw[fill=green!10, align=center, thin, rounded corners=2pt,]
(-1.7,-2) rectangle (2.1,-1) node[anchor=center] at (0.2,-1.48)
{\footnotesize <section> \\ \tiny divided section of main content };
\filldraw[fill=green!10, align=center, thin, rounded corners=2pt,]
(-1.7,-3) rectangle (2.1,-2.1) node[anchor=center] at (0.2,-2.55)
{\footnotesize <section> \\ \tiny divided section of main content };
\filldraw[fill=green!20, align=center, thick, rounded corners=2pt,]
(2.3,-3.1) rectangle (5.1,0.2) node[anchor=center] at (3.7,-0.8)
{ <aside> \\ \tiny contains extra information \\ \tiny and related content or links };
\filldraw[ fill=green!20, align=center, thick, rounded corners=2pt,]
(-1.8,-4.3) rectangle (5.1,-3.2) node[anchor=center] at (1.7,-3.8)
{ <footer> \\ \tiny infomation about copyright, privacy policy, terms of use, etc... };
\end{tikzpicture}\\
\end{document}
答案1
不确定是否更简单,但更短...是的。看看我如何用\dosmth
更短的命令替换第一个命令。您可以对其余命令执行相同操作。
\documentclass{article}
%Font settings
\usepackage[default]{sourcesanspro}
%Support for German
\usepackage[utf8]{inputenc}
\usepackage[greek,ngerman]{babel}
\usepackage{tikz}
\newcommand{\dosmth}[7]{\filldraw[style=mystyle] (#1,#2) rectangle (#3,#4) node[anchor=center] at (#5,#6) {#7};}
\begin{document}
\tikzstyle{mystyle} = [ fill=green!20, align=center, thick, rounded corners=2pt,]
\begin{tikzpicture}[xscale=0.8, yscale=0.8,]
%( left lower edge ) rectangle (right top edge) node[anchor=center] at (x,y in rectangle)
\dosmth{-1.8}{2.9}{5.1}{1.7}{1.7}{2.25}{ <header> \\ \footnotesize contains the brandings like logo };
\filldraw[style=mystyle]
(-1.8,0.3) rectangle (5.1,1.55) node[anchor=center] at (1.7,0.9)
{ <nav> \\ \footnotesize contains navigational section of the site };
\filldraw[style=mystyle]
(-1.8,-3.1) rectangle (2.2,0.2) node[anchor=center] at (0.2,-0.5)
{\footnotesize <article> \\ \tiny web page main content };
\filldraw[style=mystyle]
(-1.7,-2) rectangle (2.1,-1) node[anchor=center] at (0.2,-1.48)
{\footnotesize <section> \\ \tiny divided section of main content };
\filldraw[style=mystyle]
(-1.7,-3) rectangle (2.1,-2.1) node[anchor=center] at (0.2,-2.55)
{\footnotesize <section> \\ \tiny divided section of main content };
\filldraw[style=mystyle]
(2.3,-3.1) rectangle (5.1,0.2) node[anchor=center] at (3.7,-0.8)
{ <aside> \\ \tiny contains extra information \\ \tiny and related content or links };
\filldraw[style=mystyle]
(-1.8,-4.3) rectangle (5.1,-3.2) node[anchor=center] at (1.7,-3.8)
{ <footer> \\ \tiny infomation about copyright, privacy policy, terms of use, etc... };
\end{tikzpicture}\\
\end{document}