在“minipage”中将“text”和“tikzpicture”保持在同一级别

在“minipage”中将“text”和“tikzpicture”保持在同一级别
\documentclass[12pt] {article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ragged2e}
\usepackage{wrapfig}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}
\def\baselinestretch{2.0}
\titleformat{\paragraph}{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\setlength{\textwidth}{18cm} 
\setlength{\textheight}{21cm}
\setlength{\evensidemargin}{-0.15cm}


\begin{document}
   If we want to display a real number in decimal point representation (non-scientific format), the character
sequence becomes \%w.pf. The character sequence \%w.pf indicates that the associated data item should be
output as a floating-point number, in non-scientific format, which occupies a field of at least w characters,
and has n figures after the decimal point.\vspace{0.5cm}\\
\begin{minipage}[c]{0.35\textwidth}
    \begin{enumerate}
        \item printf(”\%f”,12. 3456);\;$\to$
        \item printf(”\%7.4f”,12. 3456);\;$\to$
        \item printf(”\%7.2f”,12. 3456);\;$\to$
        \item printf(”\%-7.2f”,12. 3456);\;$\to$
        \item printf(”\%8.4f”,-12. 3456);\;$\to$
        \item printf(”\%7.4f”,-12. 3456);\;$\to$
    \end{enumerate}
\end{minipage}%
\begin{minipage}[c]{0.35\textwidth}
    \begin{tikzpicture}
        \node[draw, minimum height=1cm,minimum width=1cm](1){1};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 1](2){2};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 2](.){.};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = .](3){3};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 3](4){4};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 4](5){5};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 5](6){6};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 6](0){0};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 0]{0};
    \end{tikzpicture}\vspace{0.2cm}
    \begin{tikzpicture}
        \node[draw, minimum height=1cm,minimum width=1cm](1){1};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 1](2){2};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 2](.){.};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = .](3){3};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 3](4){4};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 4](5){5};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 5](6){6};
    \end{tikzpicture}\vspace{0.2cm}
    \begin{tikzpicture}
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 6](0){};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 0](0'){};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 0'](1){1};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 1](2){2};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 2](.){.};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = .](3){3};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 3](5){5};
    \end{tikzpicture}\vspace{0.2cm}
    \begin{tikzpicture}
        \node[draw, minimum height=1cm,minimum width=1cm](1){1};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 1](2){2};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 2](.){.};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = .](3){3};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 3](5){5};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 5](0){};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 0]{};
    \end{tikzpicture}\vspace{0.2cm}
    \begin{tikzpicture}
        \node[draw, minimum height=1cm,minimum width=1cm](-){$-$};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = -](1){1};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 1](2){2};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 2](.){.};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = .](3){3};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 3](4){4};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 4](5){5};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 5](6){6};
    \end{tikzpicture}\vspace{0.2cm}
    \begin{tikzpicture}
        \node[draw, minimum height=1cm,minimum width=1cm](-){$-$};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = -](1){1};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 1](2){2};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 2](.){.};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = .](3){3};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 3](4){4};
        \node[draw, minimum height=1cm,minimum width=1cm, right of = 4](6){6};
    \end{tikzpicture}
\end{document}

enumerate但是和中的线条tikzpicture不在同一水平。我尝试使用,vspace{}但没有帮助。我希望我的文档如下图所示。

像这样

答案1

您应该将 MWE 保持在最低限度。我删除了那些不相关的包。对于边距,您的设置对我来说没有意义。我建议您使用几何包。我不认为minipage和在这里是必要的。您可以在里面tikzpicture使用输入这些数字和小数点。放在前面以使每个框具有标准和固定高度。并使用来自包定义一个命令来连续输入多个框。\hbox to length\fbox\strut\foreachtikz

以下是代码:

\documentclass[12pt]{article}
\usepackage{pgffor}

\def\baselinestretch{2.0}

%\setlength{\textwidth}{18cm} 
%\setlength{\textheight}{21cm}
%\setlength{\evensidemargin}{-0.15cm}% doesn't make sense if you don't have twoside document. Your textwidth out of the paper 

% use geometry package instead
\usepackage[margin=1in]{geometry}

%define a new command to type those numbers with frame for you.
\newcommand{\printf}[1]{%
\foreach \n in {#1}
{%
\fbox{\hbox to 0.8cm{\strut\hfil\n\hfil}}%
}%
}


\begin{document}
If we want to display a real number in decimal point representation (non-scientific format), the character sequence becomes \%w.pf. The character sequence \%w.pf indicates that the associated data item should be output as a floating-point number, in non-scientific format, which occupies a field of at least w characters, and has n figures after the decimal point.
\begin{enumerate}
        \item printf(``\%f”,12. 3456);\;$\to$ \printf{1,2,.,3,4,5,6,0,0}
        \item printf(``\%7.4f”,12. 3456);\;$\to$ \printf{1,2,.,3,4,5,6}
        \item printf(``\%7.2f”,12. 3456);\;$\to$ \printf{,,1,2,.,3,4}
        \item printf(``\%-7.2f”,12. 3456);\;$\to$ \printf{1,2,.,3,4,,}
        \item printf(``\%8.4f”,-12. 3456);\;$\to$ \printf{$-$,1,2,.,3,4,5,6}
        \item printf(``\%7.4f”,-12. 3456);\;$\to$ \printf{$-$,1,2,.,3,4,5}
\end{enumerate}
\end{document}

在此处输入图片描述

答案2

nicematrix包装

\documentclass{article}
\usepackage{nicematrix}

\NewDocumentCommand{\printf}{ m }
{
  \begin{NiceTabular}[hvlines, corners=SE,cell-space-limits=8pt]{*{9}{wc{1em}}}
    #1
  \end{NiceTabular}
}
\begin{document}

\begin{enumerate}
  \item 
  printf(``\%f”,12. 3456);\;$\to$  \printf{ 1 & 2 & . & 3 & 4 & 5 & 6 & 0 & 0 \\
}
\item 
printf(``\%7.4f”,12. 3456);\;$\to$ \printf{ 1 & 2 & . & 3 & 4 & 5 & 6}

\item 
printf(``\%7.2f”,12. 3456);\;$\to$ \printf{&&1&2&.&3&5}
  \end{enumerate}
\end{document}

在此处输入图片描述

相关内容