键盘快捷键的多色备忘单

键盘快捷键的多色备忘单

我正在尝试制作一个个人备忘单,用于 (主要) Sublime Text 和 Openbox (Linux 窗口管理器) 中的键盘快捷键。我发现了这个漂亮的模板:

https://gist.github.com/alexander-yakushev/c773543bf9a957749f79

它几乎可以完成我想要的所有功能,除了能够用不同的颜色为不同的键部分着色会非常有用。我认为关键在于这里第 73-94 行中键环境的定义:

\NewEnviron{keys}[1]{
  % \begin{center}
  \smallskip
  \begin{tikzpicture}
      \rowcolors{1}{}{TableRow}
      \centering
      \node (tbl) [inner sep=0pt] {
        \begin{tabular}{p{4.2cm}p{3.25cm}}
          \rowcolor{TableHead}
          \multicolumn{2}{l}{\normalsize\textbf{\color{white}{#1}}}\parbox{0pt}{\rule{0pt}{0.3ex+\baselineskip}}\\
          \BODY
          \arrayrulecolor{TableHead}\specialrule{.17em}{0em}{.2em}
        \end{tabular}};
      \begin{pgfonlayer}{background}
        \draw[rounded corners=2pt,top color=TableHead,bottom color=TableHead, draw=white]
        ($(tbl.north west)-(0,-0.05)$) rectangle ($(tbl.north east)-(0.0,0.15)$);
        \draw[rounded corners=2pt,top color=TableHead,bottom color=TableHead, draw=white]
        ($(tbl.south west)-(0.0,-0.11)$) rectangle ($(tbl.south east)-(-0.0,-0.02)$);
      \end{pgfonlayer}
    \end{tikzpicture}
  % \end{center}
} 

然而,我的 Latex 水平不够,无法解决这个问题。理想情况下,定义的键命令应该有另一个参数,以便:

  \begin{keys}{Glossary}

    Control (Ctrl) key  & \texttt{C} \\
    Alt (Meta) key      & \texttt{M} \\
    Shift key           & \texttt{S} \\
    Command (Super) key & \texttt{CMD} \\
    Function (Fn) key   & \texttt{fn} \\
    Home/end            & \texttt{fn-left / fn-right} \\
  \end{keys}

将是这样的:

  \begin{keys}{Glossary}{purple}
    Control (Ctrl) key  & \texttt{C} \\
    Alt (Meta) key      & \texttt{M} \\
    Shift key           & \texttt{S} \\
    Command (Super) key & \texttt{CMD} \\
    Function (Fn) key   & \texttt{fn} \\
    Home/end            & \texttt{fn-left / fn-right} \\
  \end{keys}

这样就可以定义部分的颜色

下面是模板的 pdf 输出的图示,用颜色注释以使其更加清晰。

在此处输入图片描述

感谢您的时间,

答案1

这是一个解决方案。我向环境中添加了两个参数{keys}:一个用于框的颜色和标题,一个用于表格中的行。

\documentclass{article}
\usepackage{calc}
\usepackage{array,booktabs}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}


\pagestyle{empty} % Turn off header and footer

\NewDocumentEnvironment{keys}{mmm}
  {
     \smallskip
     \begin{tikzpicture}
         \rowcolors{1}{}{#3}
         \centering
         \node (tbl) [inner sep=0pt] \bgroup
          \begin{tabular}{p{4.2cm}p{3.25cm}}
             \rowcolor{#2}
             \multicolumn{2}{l}{\normalsize\textbf{\color{white}{#1}}}\parbox{0pt}{\rule{0pt}{0.3ex+\baselineskip}}\\
  }
  {         
           \arrayrulecolor{#2}\specialrule{.17em}{0em}{.2em}
         \end{tabular}\egroup ;
       \begin{pgfonlayer}{background}
         \draw[rounded corners=2pt,top color=#2,bottom color=#2, draw=white]
         ($(tbl.north west)-(0,-0.05)$) rectangle ($(tbl.north east)-(0.0,0.15)$);
         \draw[rounded corners=2pt,top color=#2,bottom color=#2, draw=white]
         ($(tbl.south west)-(0.0,-0.11)$) rectangle ($(tbl.south east)-(-0.0,-0.02)$);
       \end{pgfonlayer}
     \end{tikzpicture}
  }


\begin{document}

\footnotesize

Small text.

\begin{keys}{Glossary}{red}{red!15}
  Control (Ctrl) key  & \texttt{C} \\
  Alt (Meta) key      & \texttt{M} \\
  Shift key           & \texttt{S} \\
  Command (Super) key & \texttt{CMD} \\
  Function (Fn) key   & \texttt{fn} \\
  Home/end            & \texttt{fn-left / fn-right} \\
\end{keys}

\begin{keys}{Basic}{blue}{blue!15}
  Execute command by name          & \texttt{M-x} \\
  Cancel command                   & \texttt{C-g} \\
  Exit Emacs                       & \texttt{C-x C-c} \\
  Help: describe a key combination & \texttt{C-h k} \\
  Help: describe a function        & \texttt{C-h f} \\
\end{keys}

\end{document}

上述代码的输出

答案2

根据 F. Pantigny 的回答,我修改了模板,使其包含原始模板的多列布局。我还将 xcolor 从

\usepackage[usenames,dvipsnames,table]{xcolor}

\usepackage[usenames,x11names,table]{xcolor}

以便能够访问 x11names 中的所有精彩颜色(在包文档中列出,但更好的概述这是

下面是完整的代码和一个小例子

%% Copyright 2020 Alexander Yakushev
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Alexander Yakushev.
%
% This work consists of the files latex-cheatsheet-template.tex.

\documentclass[10pt,english,landscape]{article}
\usepackage{multicol}
\usepackage{calc}
\usepackage[landscape]{geometry}
\usepackage{color,graphicx,overpic}

\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{amsfonts}
\usepackage{array,booktabs}
\usepackage{textcomp}
\usepackage[usenames,x11names,table]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{colortbl}
\usepackage{tikz}
\usepackage{environ}

\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\geometry{top=-0.5cm,left=1cm,right=1cm,bottom=1cm}

\pagestyle{empty} % Turn off header and footer

% \renewcommand\rmdefault{phv} % Arial
% \renewcommand\sfdefault{phv} % Arial

% Redefine section commands to use less space
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}%
  {-1ex plus -.5ex minus -.2ex}%
  {0.5ex plus .2ex}%x
  {\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
  {-1explus -.5ex minus -.2ex}%
  {0.5ex plus .2ex}%
  {\normalfont\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
  {-1ex plus -.5ex minus -.2ex}%
  {1ex plus .2ex}%
  {\normalfont\small\bfseries}}
\makeatother

\setcounter{secnumdepth}{0} % Don't print section numbers
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0.5ex}

\definecolor{TableHead}{rgb}{0.353, 0.329, 0.667}
\definecolor{TableRow}{rgb}{0.816, 0.812, 0.902}




\NewDocumentEnvironment{keys}{mmm}
  {
     \smallskip
     \begin{tikzpicture}
         \rowcolors{1}{}{#3}
         \centering
         \node (tbl) [inner sep=0pt] \bgroup
          \begin{tabular}{p{4.2cm}p{3.25cm}}
             \rowcolor{#2}
             \multicolumn{2}{l}{\normalsize\textbf{\color{white}{#1}}}\parbox{0pt}{\rule{0pt}{0.3ex+\baselineskip}}\\
  }
  {         
           \arrayrulecolor{#2}\specialrule{.17em}{0em}{.2em}
         \end{tabular}\egroup ;
       \begin{pgfonlayer}{background}
         \draw[rounded corners=2pt,top color=#2,bottom color=#2, draw=white]
         ($(tbl.north west)-(0,-0.05)$) rectangle ($(tbl.north east)-(0.0,0.15)$);
         \draw[rounded corners=2pt,top color=#2,bottom color=#2, draw=white]
         ($(tbl.south west)-(0.0,-0.11)$) rectangle ($(tbl.south east)-(-0.0,-0.02)$);
       \end{pgfonlayer}
     \end{tikzpicture}
  }


\begin{document}


\raggedright\

\begin{center}
  \Large{\underline{My cheatsheet}}
\end{center}

\footnotesize

% change when one column isn't enough, up to 3 columns will work
\begin{multicols}{2} 

\centering\section{Sublime Text}

\begin{keys}{Move text}{DeepPink4}{DeepPink4!35}
    Control (Ctrl) key  & \texttt{C} \\
    Alt (Meta) key      & \texttt{M} \\
    Shift key           & \texttt{S} \\
    Command (Super) key & \texttt{CMD} \\
    Function (Fn) key   & \texttt{fn} \\
    Home/end            & \texttt{fn-left / fn-right} \\
\end{keys}

\begin{keys}{Basic}{DarkOrange1}{DarkOrange1!35}
    Execute command by name          & \texttt{M-x} \\
    Cancel command                   & \texttt{C-g} \\
    Exit Emacs                       & \texttt{C-x C-c} \\
    Help: describe a key combination & \texttt{C-h k} \\
    Help: describe a function        & \texttt{C-h f} \\
\end{keys}

\columnbreak\

\centering\section{Openbox}


\begin{keys}{Glossary}{SpringGreen4}{SpringGreen4!35}
    Control (Ctrl) key  & \texttt{C} \\
    Alt (Meta) key      & \texttt{M} \\
    Shift key           & \texttt{S} \\
    Command (Super) key & \texttt{CMD} \\
    Function (Fn) key   & \texttt{fn} \\
    Home/end            & \texttt{fn-left / fn-right} \\
\end{keys}



\end{multicols}

\end{document}

相关内容