I want to write an algorithm in latex. But after compiling, it looks like that: enter image description here As it looks, keywords like "Input", "Initialize","while", "end while" and "Output" don't appear in bold, I wonder if there is something wrong and how I can correct it.

        \caption{Title of the Algorithm}
            \REQUIRE some words.  % this command shows "Input"
            \ENSURE ~\\           % this command shows "Initialized"
            some text goes here ... \\
            \WHILE {\emph{not converged}}
            \STATE ... \\  % line number at left side
            \RETURN this is the lat part.  % this command shows "Output"

Besides, I used a template from Internet, and its introduction is as follows. Thanks for your help!

\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.50cm]{geometry} %页边距
\CTEXsetup[format={\Large\bfseries}]{section} %设置章标题居左
\setmainfont{STSong}   % 宋体
\usepackage{amsmath, amsfonts, amssymb} % math equations, symbols
\usepackage{color}      % color content
\usepackage{graphicx}   % import figures
\usepackage{url}        % hyperlinks
\usepackage{bm}         % bold type for equations
\renewcommand{\algorithmicrequire}{ \textbf{Input:}}     % use Input in the format of Algorithm  
\renewcommand{\algorithmicensure}{ \textbf{Initialize:}} % use Initialize in the format of Algorithm  
\renewcommand{\algorithmicreturn}{ \textbf{Output:}}     % use Output in the format of Algorithm  
\usepackage{fancyhdr} %设置页眉、页脚
\usepackage{hyperref} %bookmarks
\hypersetup{colorlinks, bookmarks, unicode} %unicode
\author{ 陈海硕}
\affil{ 统计学院 }
  • Have a look at the listings package. – susis strolch Jul 15 at 4:04
  • Hi and welcome. Please give a fully compilable code. – AndréC Jul 15 at 5:28

On the macOS 10.15, the warning says that the font TU/STSong(0)/b/n (font STSong bold) was unavailable (it doesn't exist) and that instead LaTeX used font TU/STSong(0)/m/n (font STSong).

Basically, you can't have bold (also italic) text with this set of fonts because this particular font doesn't exist.

Just delete the line \setmainfont{STSong} should resolve the issue or use another font that has both bold and italic shapes, e.g., Times New Roman.

enter image description here

| improve this answer | |
  • It works! Thank you! When I delete this line. The keywords appear in bold. – Hahashuo Jul 15 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.