itemize 环境中的 hfill

itemize 环境中的 hfill

生成以下内容的正确/直接方法是什么?它就像一个没有边框的表格,但第一列是分项的,或者我应该使用minipage。我也尝试过,hfill但没有成功?

在此处输入图片描述

答案1

这里的老旧tabbing环境非常便利!

\documentclass{article}

\usepackage{pifont}
\usepackage{amsmath}

\newcommand{\titem}{\ding{226}\quad}

\begin{document}

\begin{itemize}
\item \begin{tabbing}
Logical Operators\qquad \= greater or equal\qquad \= \kill
Matlab uses \emph{mostly} standard relational operators \\
\titem equal              \> $==$ \\
\titem \textbf{not} equal \> $\sim=$ \\
\titem greater than       \> $>$ \\
\titem less than          \> $<$ \\
\titem greater or equal   \> $>=$ \\
\titem less or equal      \> $<=$
\end{tabbing}

\item \begin{tabbing}
Logical Operators\qquad \= greater or equal\qquad \= \kill
Logical Operators   \> elementwise \> short-circuit (scalars) \\
\titem And          \> \&          \> \&\& \\
\titem Or           \> $|$         \> $||$ \\
\titem \textbf{Not} \> $\sim$  \\
\titem Xor          \> xor  \\
\titem All true     \> all \\
\titem Any true     \> any
\end{tabbing}

\end{itemize}

\end{document}

在此处输入图片描述

如果您愿意的话,可以添加颜色。

答案2

此方法用于tabular使用该包新定义列 L 和 R 的表array。蓝色列是使用列规范创建的>{$\color{blue}}L{1cm}<{$}

\documentclass{article}
\usepackage{array}
\usepackage{pifont}
\usepackage{xcolor}
\usepackage{amsmath}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

    \begin{itemize}
        \item Matlab uses \emph{mostly} standard relational operators \\
        \begin{tabular}{>{\ding{226}}R{1cm}<{}@{\hspace{1mm}}L{3cm}>{$\color{blue}}L{1cm}<{$}}
            & equal & == \\
            & \textbf{not} equal & \sim= \\
            & greater than & > \\
            & less than & < \\
            & greater or equal & >= \\
            & less or equal & <= \\
        \end{tabular}
        \item Logical Operators \hspace{1.7cm} elementwise \hspace{.4cm} short-circuit (scalars) \\
        \begin{tabular}{>{\ding{226}}R{1cm}<{}@{\hspace{1mm}}L{3cm}>{$\color{blue}}L{2cm}<{$}>{$\color{blue}}L{1cm}<{$}}
            & And & \& & \&\& \\
            & Or & | & || \\
            & \textbf{Not} & \sim&  \\
            & Xor & \text{xor}&  \\
            & All true & \text{all}&  \\
            & Any true & \text{any}&  \\
        \end{tabular}
    \end{itemize}

\end{document}

在此处输入图片描述

答案3

这里我使用\makeboxes 来解决这个问题。我设置了一些启用宏,\mbl用于宽度为 的左对齐框\myindent\tcbl蓝色文本。

在 MWE 中,\myindent设置为 1in,但可以更改。我还使用了默认的beamer缩进图标。

\documentclass{beamer}
\def\myindent{1in}
\newcommand\mbl[1]{\makebox[\myindent][l]{#1}}
\newcommand\tcbl[1]{\textcolor{blue}{#1}}
\begin{document}
\begin{frame}
\begin{itemize}
\item MATLAB uses \textit{mostly} standard relational operators
\begin{itemize}
\item\mbl{equal}\tcbl{$==$}
\item\mbl{\textbf{not} equal}\tcbl{$\sim=$}
\item\mbl{greater than}\tcbl{$>$}
\item\mbl{less than}\tcbl{$<$}
\item\mbl{greater or equal}\tcbl{$>=$}
\item\mbl{less or equal}\tcbl{$<=$}
\end{itemize}
\item \makebox[\dimexpr\myindent+22pt\relax][l]{Logical operators}%
      \mbl{elementwise}%
      short-circuit (scalars)
\begin{itemize}
\item\mbl{And}\mbl{\tcbl{$\&$}}\tcbl{$\&\&$}
\item\mbl{Or}\mbl{\tcbl{$|$}}\tcbl{$||$}
\item\mbl{\textbf{Not}}\tcbl{$\sim$}
\item\mbl{Xor}\tcbl{xor}
\item\mbl{All true}\tcbl{all}
\item\mbl{Any true}\tcbl{any}
\end{itemize}
\end{itemize}

\end{frame}
\end{document}

在此处输入图片描述

可以使用宏进一步简化输入\tabitem{}{}{}

\documentclass{beamer}
\def\myindent{1.1in}
\newcommand\mbl[1]{\makebox[\myindent][l]{#1}}
\newcommand\tcbl[1]{\textcolor{blue}{#1}}
\newcommand\tabitem[3]{\item\mbl{#1}\mbl{\tcbl{#2}}\mbl{\tcbl{#3}}}
\begin{document}
\begin{frame}
\begin{itemize}
\item MATLAB uses \textit{mostly} standard relational operators
\begin{itemize}
\tabitem{equal}{$==$}{}
\tabitem{\textbf{not} equal}{$\sim=$}{}
\tabitem{greater than}{$>$}{}
\tabitem{less than}{$<$}{}
\tabitem{greater or equal}{$>=$}{}
\tabitem{less or equal}{$<=$}{}
\end{itemize}
\item \makebox[\dimexpr\myindent+22pt\relax][l]{Logical operators}%
      \mbl{elementwise}%
      short-circuit (scalars)
\begin{itemize}
\tabitem{And}{$\&$}{$\&\&$}
\tabitem{Or}{$|$}{$||$}
\tabitem{\textbf{Not}}{$\sim$}{}
\tabitem{Xor}{xor}{}
\tabitem{All true}{all}{}
\tabitem{Any true}{any}{}
\end{itemize}
\end{itemize}
\end{frame}
\end{document}

相关内容