更改伪代码的样式

更改伪代码的样式

我怎样才能在伪代码中用粗体和大写字母编写 if 、 while 、 else ,例如如果 尽管而不是像包中默认定义的那样

\begin{document}
\centerline {\Large {\"U}bungsblatt 7}

\section{Aufgabe 4}
\begin{algorithm}
\caption{AC Controller (temp)}\label{euclid}
\begin{algorithmic}[1]
\Procedure{Control the AC}{}\\
\SetKwIF{If}{ElseIf}{Else}{IF}{then}{else if}{else}{endif}
\hspace*{\algorithmicindent} \textbf{Input:} {Temperatur of room from the sensors} \\
\hspace*{\algorithmicindent} \textbf{Output:} {Gives the right function depends on the room Temperatur}
\State $\textit{Nofaliur} \gets \text{true }\textit{}$
\While {$Nofaliur \ = \ true $}
\State{$Read \ sensor's \ data$}
\State $\textit{temp} \gets \text{Temperatur of room }\textit{}$
\If {$ Faliur \ reading \ sensor's\ data\ from\ smart\ device$}
\State {$ Call \ Techniker$}
\State $\textit{Nofaliur} \gets \text{false }\textit{}$
\Else
\If {$temp \leq18$} 
\State  {$Turn \ on \ the \ Heat$}
\EndIf
\If {$ temp>18 \ \& \ temp<25  $}
\State {$Turn \ off \ AC/Heater/Ventilator$}
\EndIf
\If {$ temp \leq 25\ \& \ temp<32  $}
\State {$Turn \ on\ the\ Ventilator$}
\EndIf
\If {$ temp \geq 32  $}
\State {$Turn \ off \ the \ AC$}
\EndIf
\EndIf
\EndWhile 

\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}

在此处输入图片描述

答案1

您需要重新定义\algorithmic<type>每个可能的关键字:

在此处输入图片描述

\documentclass{article}

\usepackage{algorithm,algpseudocode}
\usepackage{amsmath}

\newcommand{\var}{\texttt}
\newcommand{\TRUE}{\texttt{true}}
\newcommand{\FALSE}{\texttt{false}}

\algrenewcommand{\algorithmicwhile}{\textbf{WHILE}}
\algrenewcommand{\algorithmicif}{\textbf{IF}}
\algrenewcommand{\algorithmicelse}{\textbf{ELSE}}
\algrenewcommand{\algorithmicthen}{\textbf{THEN}}
\algrenewcommand{\algorithmicend}{\textbf{END}}
\algrenewcommand{\algorithmicprocedure}{\textbf{PROCEDURE}}

\begin{document}

\begin{algorithm}
  \caption{AC Controller (temp)}
  \begin{algorithmic}[1]
    \Procedure{Control the AC}{}
      \State\textbf{INPUT:} Temperature of room from the sensors
      \State\textbf{OUTPUT:} Gives the right function depends on the room temperature
      \State $\var{Nofaliur} \gets \TRUE$
      \While {$\var{Nofaliur} = \TRUE$} % ...also \While {$\var{Nofaliur}$}
        \State Read sensor's data
        \State $\var{temp} \gets \text{Temperatur of room}$
        \If {$\text{Faliur reading sensor's data from smart device}$}
          \State Call Techniker
          \State $\var{Nofaliur} \gets \FALSE$
        \Else
          \If {$\var{temp} \leq 18$} 
            \State Turn on the Heat
          \EndIf
          \If {$\var{temp} > 18\ \&\ \var{temp} < 25$}
            \State Turn off AC/Heater/Ventilator
          \EndIf
          \If {$\var{temp} \leq 25\ \&\ \var{temp} < 32$}
            \State Turn on the Ventilator
          \EndIf
          \If {$\var{temp} \geq 32$}
            \State Turn off the AC
          \EndIf
        \EndIf
      \EndWhile
    \EndProcedure
  \end{algorithmic}
\end{algorithm}

\end{document}

你会注意到,我还改变了你的一些语法用法。此外,\SetKwIFalgorithmicx风格(而是algorithm2e)。

相关内容