我正在使用 mcode 包将我的代码包含到我的文档中,但问题是,当我的代码太长并且需要多页时,程序会尝试将它们保存在一页中,因此代码的最后几行会丢失,并且不会分成两页。
我阅读了文档,但找不到答案,而且我在列表包中也遇到了同样的问题。
我查看了一些有关 minted 的问题,但对我来说它们并没有帮助。
\documentclass{book}
\usepackage{graphicx}
\usepackage{amsmath,amssymb}
\usepackage{caption}
\usepackage{color,xecolor}
\usepackage[numbered,autolinebreaks,useliterate]{mcode}
\begin{document}
\begin{figure}
\caption{A very very long code is here}
\lstinputlisting{longcode.m}
\end{figure}
\end{document}
这是可以保存在 longcode.m 文件中的代码,因为我无法在此处附加任何内容:(
%% LTE_sim _main _launcher
% eNodeB Power transmission uniformly distributed
LTE_config.switch_off_eNodeBs = 5;
LTE_config.eNodeB_arrangment = 0; % Hexagonal Ring
LTE_config.UE_walkingModel = 0; % Mobility model
%% LTE_load _params
LTE_config.TTI_length = 1e-3; % SubFrame length
% Simulation duration
LTE_config.simulation_time_tti = 100000;
LTE_config.frequency = 2e9; % Carrier Frequency
LTE_config.bandwidth = 10e6; % Bandwidth
LTE_config.UE_speed = 30/3.6; % UE speed (Km/H => m/s)
LTE_config.nr_UEs = 100; % Number of UEs
% inter eNodeB distance (Cell radius=.5)
LTE_config.inter_eNodeB_distance = 2*sqrt (500^2+(500/4)^2);
% eNodeB Power transmission (43dbm)
LTE_config.eNodeB_tx_power = 19.9526;
% Propagation Model
LTE_config.macroscopic_pathloss_model = 'cost231';
LTE_config.macroscopic_pathloss_model _settings.environment = ...
'urban_macro';
%% LTE_init _load _BLER _curves
BLER_threshold = 0.1; % Target BLER
target_BLER = 0.1; % Target BLER
%% Parameters that are ok
% simulator assume subcarrier spacing of 15 kHz
% Modulation Schemes is QPSK, 16QAM, and 64QAM
%% I am not sure :-s
% Symbols for TTI
LTE_config.cyclic_prefix = 'normal';
switch LTE_config.cyclic_prefix
case 'normal'
LTE_config.N_sym = 14;
case 'extended'
LTE_config.N_sym = 6;
otherwise
error ('CP can only be "normal" or "extended"');
end
% CQI Measurement period
LTE_config.unquantized_CQI_feedback = fulse;
% UE class
unquantized_CQI _feedback = fulse;
%% I don't khnow
% Control Overhead
% Traffic Models
% CQI Method
% Frequency Reuse Scheme
% LTE_config.switch_off_eNodeBs = 5;
LTE_config.eNodeB_arrangment = 0; % Hexagonal Ring
LTE_config.UE_walkingModel = 0; % Mobility model
%% LTE_load _params
LTE_config.TTI_length = 1e-3; % SubFrame length
% Simulation duration
LTE_config.simulation_time_tti = 100000;
LTE_config.frequency = 2e9; % Carrier Frequency
LTE_config.bandwidth = 10e6; % Bandwidth
LTE_config.UE_speed = 30/3.6; % UE speed (Km/H => m/s)
LTE_config.nr_UEs = 100; % Number of UEs
% inter eNodeB distance (Cell radius=.5)
LTE_config.inter_eNodeB_distance = 2*sqrt (500^2+(500/4)^2);
% eNodeB Power transmission (43dbm)
LTE_config.eNodeB_tx_power = 19.9526;
% Propagation Model
LTE_config.macroscopic_pathloss_model = 'cost231';
LTE_config.macroscopic_pathloss_model _settings.environment = ...
'urban_macro';
%% LTE_init _load _BLER _curves
BLER_threshold = 0.1; % Target BLER
target_BLER = 0.1; % Target BLER
%% Parameters that are ok
% simulator assume subcarrier spacing of 15 kHz
% Modulation Schemes is QPSK, 16QAM, and 64QAM
%% I am not sure :-s
% Symbols for TTI
LTE_config.cyclic_prefix = 'normal';
switch LTE_config.cyclic_prefix
case 'normal'
LTE_config.N_sym = 14;
case 'extended'
LTE_config.N_sym = 6;
otherwise
error ('CP can only be "normal" or "extended"');
end
% CQI Measurement period
LTE_config.unquantized_CQI_feedback = fulse;
% UE class
unquantized_CQI _feedback = fulse;
%% I don't khnow
% Control Overhead
% Traffic Models
% CQI Method
% Frequency Reuse Scheme
%
以下是页面上发生的情况:
那么我怎样才能将这些代码分成两页呢?
答案1
figure
,正如 David Carlisle 所评论的那样,是一个浮动,将被放入一个框中,使其无法跨页面拆分。figure
从包中删除并使用标题listings
如下:
\lstinputlisting[caption=A very very long code is here]{longcode.m}
将会完成这项工作。
完整代码:
\documentclass{book}
%\usepackage{graphicx}
%\usepackage{amsmath,amssymb}
%\usepackage{caption}
%\usepackage{color,xcolor}
\usepackage[numbered,autolinebreaks,useliterate]{mcode}
\usepackage{filecontents}
\begin{filecontents*}{longcode.m}
%% LTE_sim _main _launcher
% eNodeB Power transmission uniformly distributed
LTE_config.switch_off_eNodeBs = 5;
LTE_config.eNodeB_arrangment = 0; % Hexagonal Ring
LTE_config.UE_walkingModel = 0; % Mobility model
%% LTE_load _params
LTE_config.TTI_length = 1e-3; % SubFrame length
% Simulation duration
LTE_config.simulation_time_tti = 100000;
LTE_config.frequency = 2e9; % Carrier Frequency
LTE_config.bandwidth = 10e6; % Bandwidth
LTE_config.UE_speed = 30/3.6; % UE speed (Km/H => m/s)
LTE_config.nr_UEs = 100; % Number of UEs
% inter eNodeB distance (Cell radius=.5)
LTE_config.inter_eNodeB_distance = 2*sqrt (500^2+(500/4)^2);
% eNodeB Power transmission (43dbm)
LTE_config.eNodeB_tx_power = 19.9526;
% Propagation Model
LTE_config.macroscopic_pathloss_model = 'cost231';
LTE_config.macroscopic_pathloss_model _settings.environment = ...
'urban_macro';
%% LTE_init _load _BLER _curves
BLER_threshold = 0.1; % Target BLER
target_BLER = 0.1; % Target BLER
%% Parameters that are ok
% simulator assume subcarrier spacing of 15 kHz
% Modulation Schemes is QPSK, 16QAM, and 64QAM
%% I am not sure :-s
% Symbols for TTI
LTE_config.cyclic_prefix = 'normal';
switch LTE_config.cyclic_prefix
case 'normal'
LTE_config.N_sym = 14;
case 'extended'
LTE_config.N_sym = 6;
otherwise
error ('CP can only be "normal" or "extended"');
end
% CQI Measurement period
LTE_config.unquantized_CQI_feedback = fulse;
% UE class
unquantized_CQI _feedback = fulse;
%% I don't khnow
% Control Overhead
% Traffic Models
% CQI Method
% Frequency Reuse Scheme
% LTE_config.switch_off_eNodeBs = 5;
LTE_config.eNodeB_arrangment = 0; % Hexagonal Ring
LTE_config.UE_walkingModel = 0; % Mobility model
%% LTE_load _params
LTE_config.TTI_length = 1e-3; % SubFrame length
% Simulation duration
LTE_config.simulation_time_tti = 100000;
LTE_config.frequency = 2e9; % Carrier Frequency
LTE_config.bandwidth = 10e6; % Bandwidth
LTE_config.UE_speed = 30/3.6; % UE speed (Km/H => m/s)
LTE_config.nr_UEs = 100; % Number of UEs
% inter eNodeB distance (Cell radius=.5)
LTE_config.inter_eNodeB_distance = 2*sqrt (500^2+(500/4)^2);
% eNodeB Power transmission (43dbm)
LTE_config.eNodeB_tx_power = 19.9526;
% Propagation Model
LTE_config.macroscopic_pathloss_model = 'cost231';
LTE_config.macroscopic_pathloss_model _settings.environment = ...
'urban_macro';
%% LTE_init _load _BLER _curves
BLER_threshold = 0.1; % Target BLER
target_BLER = 0.1; % Target BLER
%% Parameters that are ok
% simulator assume subcarrier spacing of 15 kHz
% Modulation Schemes is QPSK, 16QAM, and 64QAM
%% I am not sure :-s
% Symbols for TTI
LTE_config.cyclic_prefix = 'normal';
switch LTE_config.cyclic_prefix
case 'normal'
LTE_config.N_sym = 14;
case 'extended'
LTE_config.N_sym = 6;
otherwise
error ('CP can only be "normal" or "extended"');
end
% CQI Measurement period
LTE_config.unquantized_CQI_feedback = fulse;
% UE class
unquantized_CQI _feedback = fulse;
%% I don't khnow
% Control Overhead
% Traffic Models
% CQI Method
% Frequency Reuse Scheme
%
\end{filecontents*}
\begin{document}
\lstinputlisting[caption=A very very long code is here
]{longcode.m}
\end{document}