TransWikia.com

Extra alignment tab has been changed to cr. end{keys}

TeX - LaTeX Asked on July 4, 2021

I want to create cheat sheet for my training purposes. For that I’m using latex.

Below is the latex code –

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,dvipsnames,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

% renewcommandrmdefault{phv} % Arial
% renewcommandsfdefault{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
{normalfontlargebfseries}}
renewcommand{subsection}{@startsection{subsection}{2}{0mm}%
{-1explus -.5ex minus -.2ex}%
{0.5ex plus .2ex}%
{normalfontnormalsizebfseries}}
renewcommand{subsubsection}{@startsection{subsubsection}{3}{0mm}%
{-1ex plus -.5ex minus -.2ex}%
{1ex plus .2ex}%
{normalfontsmallbfseries}}
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}

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}{normalsizetextbf{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}
}

begin{document}

raggedright

begin{center}
Large{underline{Emacs Cheatsheet}}
end{center}

footnotesize
begin{multicols}{3}

centeringsection{Basic}

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

begin{keys}{Basic}
    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{multicols}

end{document}

When I compile the code I’m getting error Extra alignment tab has been changed to cr. end{keys}.

I want some tables to be 2 columns and some tables to be 3 columns.

How can I achieve it?

One Answer

A possible answer is to add another parameter to your environment. The drawback in the code below: every columns have the same type (same width). Maybe you could consider the tabularx environment, with adjustable column width.

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,dvipsnames,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

% renewcommandrmdefault{phv} % Arial
% renewcommandsfdefault{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
    {normalfontlargebfseries}}
renewcommand{subsection}{@startsection{subsection}{2}{0mm}%
    {-1explus -.5ex minus -.2ex}%
    {0.5ex plus .2ex}%
    {normalfontnormalsizebfseries}}
renewcommand{subsubsection}{@startsection{subsubsection}{3}{0mm}%
    {-1ex plus -.5ex minus -.2ex}%
    {1ex plus .2ex}%
    {normalfontsmallbfseries}}
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}

NewEnviron{keys}[2][2]{% <-- Modified by default, 2 columns
    % begin{center}
    smallskip
    begin{tikzpicture}
    rowcolors{1}{}{TableRow}
    centering
    node (tbl) [inner sep=0pt] {
        begin{tabular}{*{#1}{p{3.25cm}}} % <-- Modified
        rowcolor{TableHead}
        multicolumn{#1}{l}{normalsizetextbf{color{white}{#2}}}parbox{0pt}{rule{0pt}{0.3ex+baselineskip}} % <-- Modified
        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}
}

begin{document}
    
    raggedright
    
    begin{center}
        Large{underline{Emacs Cheatsheet}}
    end{center}
    
    footnotesize
    begin{multicols}{2}
        
        centeringsection{Basic}
        
        begin{keys}[3]{Glossary} % <-- use the optional parameter
            Control (Ctrl) key  & texttt{C} & texttt{C key for your OS} 
            Alt (Meta) key      & texttt{M} & texttt{M Key for your OS} 
            Shift key           & texttt{S} & texttt{M Key for your OS} 
            Command (Super) key & texttt{CMD} & texttt{M Key for your OS} 
            Function (Fn) key   & texttt{fn} & texttt{M Key for your OS} 
            Home/end            & texttt{fn-left / fn-right}  & texttt{M Key for your OS} 
        end{keys}
        
        begin{keys}{Basic}
            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{multicols}
    
end{document}

Correct answer by NBur on July 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP