我在课堂上有以下内容:
\newcommand{\blacknode}[1]{
\begin{tikzpicture}
\node[draw, fill=black, text=white, rectangle, rounded corners, node distance=1mm, inner sep=5pt] %, align=center %5mm
{#1};
\end{tikzpicture}
}
当我在脚本中使用它时:
\blacknode{Python}
\blacknode{Matlab}
\blacknode{VBA}
\blacknode{\LaTeX}
\blacknode{Javascript}
\blacknode{C}
\blacknode{Ladder Logic}
\blacknode{R}
\blacknode{STL}
\blacknode{Arduino}
这是我的输出:
我如何才能改善格式?更紧凑/动态的包装和相同的高度?有没有比使用节点更好的选择?
答案1
不是太优雅但可能更接近期望的输出:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\tikzset{blacknode/.style={draw,
fill=black,
text=white,
rectangle,
rounded corners,
inner sep=5pt,
minimum height=0.7cm,
}}
\begin{tikzpicture}[every node/.style={blacknode}]
\node(python){Python};
\node[right= 0.1cm of python](matlab){Matlab};
\node[below=0.8cm of python.west, anchor=west](vba){VBA};
\node[right=0.1cm of vba](latex){\LaTeX};
\node[below=0.8cm of vba.west,anchor=west](javascript){Javascript};
\node[right=0.1cm of javascript](c){C};
\node[below=0.8cm of javascript.west,anchor=west](ladderlogic){Ladder Logic};
\node[below=0.8cm of ladderlogic.west,anchor=west](r){R};
\node[right=0.1cm of r](stl){STL};
\node[right=0.1cm of stl](arduino){Arduino};
\end{tikzpicture}
\end{document}
答案2
另一项建议来自tcbox
(tcolorbox
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\newtcbox{\blacknode}[1][black]{%
on line, colback=#1, colframe=#1, colupper=white, equal height group = blacknode, before upper=\strut, boxsep=0pt}
\begin{document}
\noindent\blacknode{Python}
\blacknode{Matlab} \\
\blacknode{VBA}
\blacknode{\LaTeX}\\
\blacknode{Javascript}
\blacknode{C}\\
\blacknode[blue!70!black]{Ladder Logic}
\blacknode{R}\\
\blacknode{STL}
\blacknode[red]{Arduino}
\end{document}
答案3
做同样事情的另一种方式——矩阵
\begin{tikzpicture}[
% node distance=5mm,
terminal/.style={
% The shape:
rectangle,
minimum size=10mm,
rounded corners=3mm,
% The rest
very thick,
draw=black!50,
fill=black,
text=white,
inner sep=5pt,
font=\ttfamily}
]
\matrix[
row sep=6pt,
column sep=2pt]{
%first row
\node (digit1) [terminal] {A};&
\node (digit1) [terminal] {Ap};&
\node (digit1)[terminal] {App};&&\\
%second row
\node (digit1) [terminal] {Appl};&
\node (digit2) [terminal] {Apple};&&
\node(digit3) [terminal] {A};&\\
};
\end{tikzpicture}
答案4
再举一个例子:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 0mm,
every node/.style = {draw, rounded corners, fill=black, text=white,
text height=3ex, text depth=0.5 ex,
outer sep=1mm}
]
\node (n1) {Python};
\node (n2) [below right=of n1.south west] {Matlab};
\node (n3) [below right=of n2.south west] {VBA};
\node (n4) [right=of n3] {\LaTeX};
\node (n5) [below right=of n3.south west] {Javascript};
\node (n6) [right=of n5] {C};
\node (n7) [below right=of n5.south west] {Ladder Logic};
\node (n8) [below right=of n7.south west] {R};
\node (n9) [right=of n5] {STL};
\node (n10)[below right=of n8.south west] {Arduino};
\end{tikzpicture}
\end{document}