「 LaTeX 」伪代码Switch-case语句编写

一、前言

        小白用LaTeX写伪代码的Switch-case框架时,尝试网络答案3小时无果,最后被官方使用手册救赎。网络上大多方法基于\usepackage{algorithmic}库,看到下段代码就能明白小白所指:

% New definitions
\algnewcommand\algorithmicswitch{\textbf{switch}}
\algnewcommand\algorithmiccase{\textbf{case}}
\algnewcommand\algorithmicassert{\texttt{assert}}
\algnewcommand\Assert[1]{\State \algorithmicassert(#1)}%
% New "environments"
\algdef{SE}[SWITCH]{Switch}{EndSwitch}[1]{\algorithmicswitch\ #1\ \algorithmicdo}{\algorithmicend\ \algorithmicswitch}%
\algdef{SE}[CASE]{Case}{EndCase}[1]{\algorithmiccase\ #1}{\algorithmicend\ \algorithmiccase}%
\algtext*{EndSwitch}%
\algtext*{EndCase}%

        但无论怎么尝试,都不能在小白的环境下运行,后来得知,\usepackage{algorithmic}与\usepackage[linesnumbered,ruled,vlined]{algorithm2e}不能共存,为了漂亮的版式怎能放弃algorithm2e,终于在官方使用手册中找到了解决方法。

二、技术

        无需自定义环境,algorithm2e库里已安排的明明白白,直接插入如下代码即可:

\Switch{the value of T}{
       \uCase{a value}{
do this\;
do that\; }
       \lCase{another value}{one line}\;
       \Case{last value}{
do this\;
break\; }
       \Other{
         for the other values\;
         do that\;
} }

三、实现效果

*亲测有效

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Robot_Starscream

祝好!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值