使用 TikZ 排版键

使用 TikZ 排版键

我正在使用一个小的 TikZ Code 来排版计算器键,总的来说效果很好。但我只有一个问题:当我只输入单行时,我希望相应的框和包含两个部分的框一样大。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[]{amsmath}
\setlength{\parskip}{1em}

\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows}

\tikzstyle{abstract}=[rectangle, draw=black, rounded corners, fill=gray!30,drop shadow, text centered,  text=black, text width=8mm]
\tikzstyle{fkey}=[rectangle, draw=black, rounded corners, fill=orange,drop shadow, text centered,  text=black, text width=8mm]
\tikzstyle{gkey}=[rectangle, draw=black, rounded corners, fill=blue!40,drop shadow, text centered,  text=black, text width=8mm]

\newcommand{\mykey}[2]{%
\begin{tikzpicture} \node (Item) [abstract, rectangle split, rectangle split parts=2]{\textbf{\scriptsize{#1}} \nodepart{second}\textbf{\tiny{#2}}};%
\end{tikzpicture}}

\newcommand{\myfkey}{%
\begin{tikzpicture} \node (Item) [fkey, rectangle split, rectangle split parts=2]{\textbf{\footnotesize{f}} \nodepart{second}};%
\end{tikzpicture}}

\newcommand{\mygkey}{%
\begin{tikzpicture} \node (Item) [gkey, rectangle split, rectangle split parts=2]{\textbf{\footnotesize{g}} \nodepart{second}};%
\end{tikzpicture}}

\newcommand{\mynumberkey}[1]{%
\begin{tikzpicture} \node (Item) [abstract]{\textbf{#1}};%
\end{tikzpicture}}


\begin{document}


 \mykey{n}{$12x$}

 \mykey{SST}{$\Delta \text{DYS}$}

 \myfkey

 \mygkey

 \mykey{Enter}{=}

\mynumberkey{3}

\end{document}

计算器键

答案1

当您定义样式时,您只需添加即可minimum height=...

例如:

\tikzset{abstract/.style={rectangle, 
       draw=black,
       rounded corners,
       fill=gray!30,
       drop shadow,
       text centered,
       text=black,
       text width=8mm,
       minimum height=0.75cm,
   }
}
\tikzstyle{fkey/.style={rectangle, 
       draw=black,
       rounded corners,
       fill=orange,
       drop shadow,
       text centered,
       text=black, 
       text width=8mm,
       minimum height=0.75cm,
  }
}
\tikzstyle{gkey/.style={rectangle, 
      draw=black,
      rounded corners,
      fill=blue!40,
      drop shadow,
      text centered,
      text=black, 
      text width=8mm,
      minimum height=0.75cm,
   }
}

在你的序言中将导致:

在此处输入图片描述

相关内容