LaTeXStudio
LaTeXStudio
这家伙很懒,什么也没写!

注册于 4年前

回答
467
文章
291
关注者
196

具体错误是什么,这样写没有什么大问题的。

代码各种漏,错。

\documentclass[a4paper,zihao=-4,UTF8]{article}
\usepackage{ctex}
\usepackage{amsmath}
\usepackage{indentfirst}
\usepackage{listings}
\lstset{language=Matlab}
\usepackage{float}
\usepackage{graphicx}
\graphicspath{{图片/}}
\usepackage{appendix}
\usepackage[table]{xcolor}
\renewcommand{\abstractname}{\zihao{3} 摘要\\}
\linespread{1.5}
\usepackage {xeCJK}
\usepackage{makecell}

\setCJKmainfont {FangSong}
% 设置正文罗马族的CJK字体,影响\rmfamily和\textrm 的字体
\setCJKsansfont {FangSong}
% 设置正文无衬线族的CJK字体,影响\sffamily和\textsf 的字体
\setCJKmonofont {FangSong}
%设置正文等宽族的CJK字体,影响\ttfamily 和 \texttt 的字体
\usepackage[center]{titlesec}
\newfontfamily\sectionef{Times New Roman}
\newCJKfontfamily\sectioncf{FangSong}
%\titleformat*{\section}{\Large\bfseries}
%\titleformat*{\subsection}{\large\bfseries}
% \titleformat{command}[shape]{format}{label}{sep}{before}[after] ,https://www.latexstudio.net/archives/7982.html


\begin{titlepage}
    \title{\fangsong }
    \author{\fangsong }
    \date{\today}
\end{titlepage}
\begin{document}
    \maketitle
    \newpage
    \begin{abstract}
        \par      某公司建筑工地开工,需要从料场配送水泥,具体各个料场的供应方案和选址亟需解决。
        \par  首先,根据供应与选址问题可以划分为规划问题.针对第一问,在给定料场位置的情况下,根据题目所给条件给出\textbf{线性规划模型},用穷举法遍历所有可能值,最终比较所有值得出最佳运输方案:
        \par 针对问题二,要改建两个新料场,因为要确定确定料场的位置和运送量,在与第一问的同样条件下。将问题二转化为\textbf{非线性规划问题}。采取二次规划的方法,利用$ matlab $的$ fmincon $函数求解,最终的方案为:\\
        
        \textbf{ 关键词}:线性规划模型、非线性规划问题、优化问题
    \end{abstract}
    
    \thispagestyle{empty}
    \newpage
    \pagenumbering{arabic}
    \begin{center}
        \tableofcontents
    \end{center}
    
    \newpage
    \section{问题重述与分析}
   某公司有6个建筑工地要开工,每个工地的位置给出。需解决两个问题:\\

   问题一:给定两个日储量20吨临时料场位于A(5,1),B(2,7)。目标是制定最佳的供应计划即考虑吨千米数在适当方案下最小\\
   问题二 :考虑建立两个新的日存储量为20吨的料场,进一步减少吨千米数
    \par

    \section{基本假设}
    由于本次是规划类问题,便于模型的建立与求解,做出以下假设。
    \par (1)从料场到工地之间均有直线道路连接。
    \par(2)建筑工地水泥用量和料场水泥日存储量均不发生改变。
    \par(3)不考虑运输过程由于道路等因素出现的影响。

    
    \section{符号说明}
    \begin{table}[H]
        \setlength{\abovecaptionskip}{0pt}
            \setlength{\belowcaptionskip}{10pt}
        %     \captionsetup{margin=10pt , font=small,
            %     labelfont=bf, labelsep=period,
            %     skip=5pt    , labelformat=empty}[ 符号一览表} %表一加粗 居中
    \setlength{\tabcolsep}{20mm}{%7可随机设置,调整到适合自己的大小为止
        \caption{符号一览表}
        \begin{tabular}{c | c}
            \hline
            符号    &   \quad 含义 \\
            \rowcolor{black!20}    
        $f$    &    总的吨千米数 \\
            \hline     \rowcolor{black!5}    
                $ x_i$ &     临时料场的横坐标\\
            \rowcolor{black!20}    
            $ x_j$    &  临时料场的横坐标\\
            \rowcolor{black!5}    
        $ a_i $&  工地的横坐标\\
            \rowcolor{black!20}    
                $ b_i $&  工地的纵坐标\\
            \rowcolor{black!5}    
        $ e_j $&  日储量(吨)\\
            \rowcolor{black!20}    
                $ X_{ij} $&  运送量(吨)\\
            \rowcolor{black!5}    
        
        
            \hline
        \end{tabular}
    }
\end{table}


\setcounter{page}{1}

\section{模型的建立与求解}
\subsection{模型的建立}
记工地的位置为$ (a_i,b_i) $,水泥日用量为$ di,i=1,…,6 $;料场位置为$ (x_j,y_j) $,日储量为$e_ j,j=1,2 $;从料场$ j $向工地i的运送量为$ X_{ij} $。则由题目给出的条件给出线性规划模型:
目标函数为
\begin{equation}
    min f=\sum_{j=1}^{2}\sum_{i=1}^{6}X_ij\sqrt{(x_j-a_i)^2+(y_j-b_i)^2}
\end{equation}
约束条件:
\begin{equation}
    s.t.
    \left\{
    \begin{array}    {lr}
        \sum_{j=1}^{2}X_{ij}=d_i,i=1,2,\dots,6\\
        \sum_{j=1}^{2}X_{ij} \leq e_i,i=1,2.\\
        X_{ij}\geq 0,i=1,2,\dots,6,j=1,2.
    \end{array}
    \right.
\end{equation}
\par 同时根据两个问题的条件可设:
\\ 当用临时料场时决策变量为:$ X_{ij} $,
\\当不用临时料场时决策变量为:$ X_{ij} $,$ x_j $,$ y_j $


\subsection{模型的求解}
\subsubsection{使用临时料场的情形}
使用两个临时料场$ A(5,1),B(2,7) $.求从料场$ j $向工地$ i $的运送量为$ X_{ij} $,在各工地用量必须满足和各料场运送量不超过日储量的条件下,使总的吨千米数最小,这是线性规划问题. 线性规划模型目标函数:
\begin{equation}
min f=\sum_{j=1}^{2}\sum_{i=1}^{6}X_{ij}aa(i,j)X_{ij}
\end{equation}
约束条件:
\begin{equation}
s.t.
\left\{
\begin{array}{lr}    
    \sum_{j=1}^{2}X_{ij}=d_i,i=1,2,\dots,6\\
    \sum_{j=1}^{2}X_{ij} \leq e_i,i=1,2,\dots,6\\
\end{array}
\right.
\end{equation}
其中$aa(i,j)=\sqrt{(x_j-a_i)^2+(y_j-b_i)^2},i=1,2,\dots,j=1,2,$为常数
\\ 设 $  X_{11}=X_{1}$
, $ X_{21}= X_{ 2} $, $ X_{31}= X_{3} $
, $ X_{41}= X_{4} $
, $ X_{51}= X_{5} $,$  X_{61}= X_{6} $,
$ X_{12}= X_{7} $
, $ X_{22}= X_{8} $,$  X_{32}= X_{9} $
,$  X_{42}= X_{10} $
, $ X_{52}= X_{11} $, $ X_{62}=X_{12} $
\\使用$ fmincon $函数,求出方案为:
\begin{table}[H]
    \setlength{\tabcolsep}{4mm}{        
        \begin{tabular}{|l|c|c|c|c|c|c|}
            \hline    \rowcolor{black!20}    
            \quad&1&2&3&4&5&6\\
            \hline
            \makecell{料场A向各工地 \\运送水泥量(吨)}&3.0&5.0&0.0&7.9&0.0&1.0\\
            \hline
                \makecell{料场B向各工地 \\运送水泥量(吨)}&0.0&0.0&4.0&0.0&6.0&10.0\\
            \hline
    \end{tabular}     }

\end{table}
总的吨千米数为138.2815.

\subsubsection{改建两个新料场的情形}
改建两个新料场,要同时确定料场的位置(xj,yj)和运送量$ X_{ij} $,在同样条件下使总吨千米数最小。这是非线性规划问题。
非线性规划模型为:
\begin{equation}
    min f=\sum_{j=1}^{2}\sum_{i=1}^{6}X_{ij}\sqrt{(x_j-a_i)^2+(y_j-b_i)^2}
\end{equation}
约束条件:
\begin{equation}
    s.t.
    \left\{
    \begin{array}{lr}    
        \sum_{j=1}^{2}X_{ij}=d_i,i=1,2,\dots,6\\
        \sum_{j=1}^{2}X_{ij} \leq e_i,i=1,2,\dots,6\\
    \end{array}
    \right.
\end{equation}
设 $ X_11=X_1
, X_21= X_ 2, X_31= X_ 3
, X_41= X _4
, X_51= X_ 5,X_61= X_ 6
X_12= X _7
, X_22= X_ 8,X_32= X_ 9
, X_42= X_10
, X_52= X_11, X_62= X_12
x_1=X_13
, y_1=X_14
, x_2=X_15
, y_2=X_16 $
\par 由于位置未确定,将非线性规划模型建立起来,利用matlab的fmiincon函数对其进行求解。取第一问的料场位置及供应方案作为初值,最终得到求值结果:
\begin{table}[H]
        \setlength{\tabcolsep}{1mm}{
            \begin{tabular}{|l|c|c|c|c|c|c|}
                \hline     \rowcolor{black!20}    
                \quad&1&2&3&4&5&6\\
                \hline
                \makecell{料场A向各工地 \\运送水泥量(吨)}&2.9308&4.6211&3.8663&6.9324&1.5444&0.0253\\
                \hline
                \makecell{料场B向各工地 \\运送水泥量(吨)}&0.0692&0.3789&0.1337&0.0676&4.556&10.9747\\
                \hline
        \end{tabular}     }
    
\end{table}
新建料场C(5.7419,4.9914)、D(7.2500,7.2500)
总的吨千米数为89.9233.




\subsubsection{改建料场方案的优化}
\par 使用$ matlab $的$ fmincon $函数,可以将第二问求出的料场位置及供应方案作为初值带入进行优化。最终得到结果:

\begin{table}[H]
     \setlength{\tabcolsep}{1mm}{
             \begin{tabular}{|l|c|c|c|c|c|c|}
             \hline     \rowcolor{black!20}    
             \quad&1&2&3&4&5&6\\
             \hline
             \makecell{料场A向各工地 \\运送水泥量(吨)}&2.9974&4.9865&3.9950&6.9972&1.0196&0.0010\\
             \hline
                 \makecell{料场B向各工地 \\运送水泥量(吨)}&0.0026& 0.0135& 0.0050& 0.0028& 4.9804& 10.9990\\
             \hline
     \end{tabular}     }

\end{table}
新建料场C(5.7419,4.9914)、D(7.2500,7.2500)
总的吨千米数为89.9233.


\section{模型的评价}
优点:可以较好应用实际情况
缺点:未必能求出全局最优解,模型的解法依赖于初值的选取。


\par 缺点:

\begin{thebibliography}{99}
    
    \bibitem{book1}姜启源,谢金星,叶俊, 《数学模型》,高等教育出版社
    
\end{thebibliography}
\begin{appendices}

    \section{附录-matlab代码}
\lstset{language = matlab,
    backgroundcolor = \color{yellow!10}, % 背景色:淡黄
    basicstyle = \small\ttfamily, % 基本样式 + 小号字体
    rulesepcolor= \color{gray}, % 代码块边框颜色
    breaklines = true, % 代码过长则换行
    numbers = left, % 行号在左侧显示
    numberstyle = \small, % 行号字体
    keywordstyle = \color{blue}, % 关键字颜色
    commentstyle =\color{green!100}, % 注释颜色
    stringstyle = \color{red!100}, % 字符串颜色
    frame = shadowbox, % 用(带影子效果)方框框住代码块
    showspaces = false, % 不显示空格
    columns = fixed, % 字间距固定
}
    %\lstinline[extendedchars=false]    
    %escapeinside={} % 特殊自定分隔符:
 \begin{lstlisting}
    第一问:
    模型:
        function f=fun(X)
        a=[1.25 8.75 0.5 5.75 3 7.25];%各工地位置的横坐标;
        b=[1.25 0.75 4.75 5 6.5 7.25];%各工地位置的纵坐标;
        x1=5*ones(1,6);
        y1=ones(1,6);
        x2=2*ones(1,6);
        y2=7*ones(1,6);
        f=sqrt((x1-a).^2+(y1-b).^2)*[X(1) X(2) X(3) X(4) X(5) X(6)]'+sqrt((x2-a).^2+(y2-b).^2)*[X(7) X(8) X(9) X(10) X(11) X(12)]';
        %X1,X2,X3,X4,X5,X6为新建料场A(5,1)向各工地运送的水泥吨数;
        %X6.X7.X8.X9.X10,X11,X12为新建料场B(2,7)向各工地运送的水泥吨数;
        求解:
        e1=20;e2=20;%料场水泥日储量
        d=[3 5 4 7 6 11];%各个工地水泥日用量
        x0=ones(12,1);%初值
        A=[1 1 1 1 1 1 0 0 0 0 0 0;0 0 0 0 0 0 1 1 1 1 1 1];
        b=[e1;e2];
        Aeq=[1 0 0 0 0 0 1 0 0 0 0 0;0 1 0 0 0 0 0 1 0 0 0 0;0 0 1 0 0 0 0 0 1 0 0 0;0 0 0 1 0 0 0 0 0 1 0 0;0 0 0 0 1 0 0 0 0 0 1 0;0 0 0 0 0 1 0 0 0 0 0 1]
        beq=d';
        VLB=zeros(12,1);
        VUB=[d';d'];
        [x,fval]=fmincon('fun',x0,A,b,Aeq,beq,VLB,VUB)
        第二问:
        模型:
        function f=fun1(X)
        a=[1.25 8.75 0.5 5.75 3 7.25];%各工地位置的横坐标;
        b=[1.25 0.75 4.75 5 6.5 7.25];%各工地位置的纵坐标;
        f=X(1)*sqrt((X(13)-a(1))^2+(X(14)-b(1))^2)+X(2)*sqrt((X(13)-a(2))^2+(X(14)-b(2))^2)+X(3)*sqrt((X(13)-a(3))^2+(X(14)-b(3))^2)+X(4)*sqrt((X(13)-a(4))^2+(X(14)-b(4))^2)+X(5)*sqrt((X(13)-a(5))^2+(X(14)-b(5))^2)+X(6)*sqrt((X(13)-a(6))^2+(X(14)-b(6))^2)+X(7)*sqrt((X(15)-a(1))^2+(X(16)-b(1))^2)+X(8)*sqrt((X(15)-a(2))^2+(X(16)-b(2))^2)+X(9)*sqrt((X(15)-a(3))^2+(X(16)-b(3))^2)+X(10)*sqrt((X(15)-a(4))^2+(X(16)-b(4))^2)+X(11)*sqrt((X(15)-a(5))^2+(X(16)-b(5))^2)+X(12)*sqrt((X(15)-a(6))^2+(X(16)-b(6))^2);
        %X1,X2,X3,X4,X5,X6为新建料场A(5,1)向各工地运送的水泥吨数;
        %X6.X7.X8.X9.X10,X11,X12为新建料场B(2,7)向各工地运送的水泥吨数;
        求解:
        e1=20;e2=20;%料场水泥日储量
        d=[3 5 4 7 6 11];%各个工地水泥日用量
        x0=[3 5 0 7 0 1 0 0 4 0 6 10 5 1 2 7];%初值取(1)的结果和临时料场的坐标
        A=[1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0];
        b=[e1;e2];
        Aeq=[1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0;0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0;0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0;0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0;0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0;0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0];
        beq=d';
        VLB=zeros(16,1);
        VUB=[];
        [x,fval]=fmincon('fun1',x0,A,b,Aeq,beq,VLB,VUB)
        x1=[2.9308 4.6211 3.8663 6.9324 1.5444 0.0253 0.0692 0.3789 0.1337 0.0676 4.4556 10.9747 5.7419 4.9914 7.2500 7.2500]%初值取的是上面计算结果
        [y,fvaly]=fmincon('fun1',x1,A,b,Aeq,beq,VLB,VUB)
    \end{lstlisting}
\end{appendices}
\end{document} 

我这里测试的样例是没有问题的,可以看看下面的例子:
image.png

例子代码:
0426.zip

仔细看看说明书,提到了的,label 后面要加上 % 来规避空格。

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{showframe}
\title{The Dog}

\begin{document}

The dog or domestic dog (Canis familiaris or Canis lupus familiaris) is a domesticated descendant of the wolf, and is characterized by an upturning tail. The dog is derived from an ancient, extinct wolf, and the modern wolf is the dog's nearest living relative. The dog was the first species to be domesticated, by hunter–gatherers over 15,000 years ago, before the development of agriculture. Due to their long association with humans, dogs have expanded to a large number of domestic individuals and gained the ability to thrive on a starch-rich diet that would be inadequate for other canids.

The dog has been selectively bred over millennia for various behaviors, sensory capabilities, and physical attributes. Dog breeds vary widely in shape, size, and color. They perform many roles for humans, such as hunting, herding, pulling loads, protection, assisting police and the military, companionship, therapy, and aiding disabled people. Over the millennia, dogs became uniquely adapted to human behavior, and the human-canine bond has been a topic of frequent study. This influence on human society has given them the sobriquet of "man's best friend".

The dog or domestic dog (Canis familiaris or Canis lupus familiaris) is a domesticated descendant of the wolf, and is characterized by an upturning tail. The dog is derived from an ancient, extinct wolf, and the modern wolf is the dog's nearest living relative. The dog was the first species to be domesticated, by hunter–gatherers over 15,000 years ago, before the development of agriculture. Due to their long association with humans, dogs have expanded to a large number of domestic individuals and gained the ability to thrive on a starch-rich diet that would be inadequate for other canids.

\begin{figure}[!t]
    \subfigure[]{%
        \begin{minipage}[b]{\columnwidth}
            \centering
            \label{fig_test_case1:a}%
            \includegraphics[width=\columnwidth]{dog.jpeg}
        \end{minipage}
    }\\
    \subfigure[]{%
        \begin{minipage}[b]{\columnwidth}
            \centering
            \label{fig_test_case1:b}%
            \includegraphics[width=\columnwidth]{dog.jpeg}
        \end{minipage}
    }
    \caption{The dog or domestic dog is a domesticated descendant of the wolf. (a) Dog 1; (b) Dog 2.}
    \label{fig_test_case1}
\end{figure}

The dog has been selectively bred over millennia for various behaviors, sensory capabilities, and physical attributes. Dog breeds vary widely in shape, size, and color. They perform many roles for humans, such as hunting, herding, pulling loads, protection, assisting police and the military, companionship, therapy, and aiding disabled people. Over the millennia, dogs became uniquely adapted to human behavior, and the human-canine bond has been a topic of frequent study. This influence on human society has given them the sobriquet of "man's best friend".

The dog or domestic dog (Canis familiaris or Canis lupus familiaris) is a domesticated descendant of the wolf, and is characterized by an upturning tail. The dog is derived from an ancient, extinct wolf, and the modern wolf is the dog's nearest living relative. The dog was the first species to be domesticated, by hunter–gatherers over 15,000 years ago, before the development of agriculture. Due to their long association with humans, dogs have expanded to a large number of domestic individuals and gained the ability to thrive on a starch-rich diet that would be inadequate for other canids.

\end{document}

image.png

这样的排版方式是竖排了,不是限制文本宽度变成了换行了而已。简单一点自己 shortstack 单独设置行间距。如果不多的情况,临时解决。

与其这样不如给版面画个背景呢,用margin的方式实现批注。

完整的代码在哪里?最好有个复现代码,方便给出答案!

代码不完整,我这里整体调整如下:

\documentclass{article}
\usepackage{pgf,tikz}
\usetikzlibrary{shapes}
\makeatletter
\pgfdeclareshape{document}{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
% ... and possibly more
\backgroundpath{% this is new
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% compute corner of ``flipped page''
\pgf@xc=\pgf@xb \advance\pgf@xc by-5pt % this should be a parameter
\pgf@yc=\pgf@yb \advance\pgf@yc by-5pt
% construct main path
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
% add little corner
\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[shade,draw,shape=document,inner sep=2ex]  (x)  {Remark};
\node[fill=yellow!80!black,draw,ellipse,double]
at ([shift=(-80:3cm)]x) (y) {Use Case};
\draw[dashed] (x) -- (y);
\end{tikzpicture}

\end{document}

image.png

没看懂问题是什么,看看这个代码:

 \documentclass{IEEEtran}

\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}

 \begin{algorithm}[H]
 \caption{Algorithm for ...}
 \begin{algorithmic}[1]
 \renewcommand{\algorithmicrequire}{\textbf{Input:}}
 \renewcommand{\algorithmicensure}{\textbf{Output:}}
 \REQUIRE in
 \ENSURE  out
 \\ \textit{Initialisation} :
  \STATE first statement
 \\ \textit{LOOP Process}
  \FOR {$i = l-2$ to $0$}
  \STATE statements..
  \IF {($i \ne 0$)}
  \STATE statement..
  \ENDIF
  \ENDFOR
 \RETURN $P$
 \end{algorithmic}
 \end{algorithm}

\end{document} 

image.png

什么信息都没有,就这样的问题,无法回答。

发布
问题