I need to typeset some very large numbers that span a number of lines, is there a way in LaTeX to do this?
-
Do you need the subsequent lines to wrap around the numbers?– EmreApr 15, 2011 at 19:28
-
Does tex.stackexchange.com/questions/6171/… help?– CaramdirApr 15, 2011 at 19:29
-
@Emre yes they have to wrap.– mathspashaApr 15, 2011 at 19:39
-
@mathpasha I am not sure, if you are looking to typeset, big integers or large sized numbers as in font-size. Can you please clarify?– yannislApr 15, 2011 at 19:49
3 Answers
For typesetting large integers you can use the package numprint
.
You will need to set the thousands separator to your liking (I have used a space).
Here, is a minimal that can do this. The number was generated using Heiko Oberdiek's bigintcalc
. The sample number is the 1279 Mersenne number calculated with the macro \Mersenne
, shown in the minimal below. As this is calculated using a power function it takes about 15 seconds to process!
\documentclass{article}
\usepackage[english]{babel}
\usepackage{numprint}
\usepackage{bigintcalc}
\begin{document}
\npthousandsep{ }
\def\Mersenne#1{%
\begingroup
\par\noindent\parindent=0pt
$M_{#1}=$\par
\def\exponent##1{\bigintcalcPow{2}{##1}}%
\numprint{\bigintcalcSub{\exponent{#1}}{1}}
\endgroup
}
\Mersenne{1279}
\end{document}
-
To use thin spaces as separators,
\npthousandsep{\ensuremath\,\allowbreak}
would work. Better in my opinion than full spaces.– lblbApr 11, 2017 at 21:57
That depends on what you are trying to achieve; one possibility would be to explicitly select the font size (using Computer Modern fonts this requires the fix-cm
package):
\documentclass{article}
\usepackage{fix-cm}
\begin{document}
{\fontsize{40}{48}\selectfont 2}
{\fontsize{90}{108}\selectfont 2}
\end{document}
-
1Only two other people like your joke? What a pity! It is beautiful. Nov 10, 2013 at 9:30
numprint
seems to fail on very large numbers, e.g. the number 2011^2011 requested in How to typeset long numbers in LaTeX. One possibility in such cases is to use siunitx
and its group separator option as follows (number computed in computer algebra package):
...2 pages later...
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\num[group-separator={\ifmmode\egroup\egroup\)\egroup\ \bgroup\(\bgroup\bgroup\fi}]{14510219094756835443971804257188873072794015545666081939388855749525896884654481242616934781472275243051888663874155206933903154198120231191628992301817135048200098980176752739362987878664059532850107984545109970319612751146817229127042379603090727086757619024725981449720739503384463675281844597701405345770843465000975070415089613332211172182623690270574999349969317078016313807025422481160546843537968347603649315792489605777834323805460413034900278406748673158431279064662352847958818691708253398792960152785338035354737318651122455328213785355488400398210887854142389370989758234640130506260675874047790025842440885467711037139174297690267704869910896371907830244052230101607377315283106967320104784230128581678356733651972721303261927010476541549034821238262101145454460744235581503300804731781313297449779427755185487515045090431608215979542642856019280583688925217816428602650546812760023727355869719417344689058172044429829389003403686273002229187524537247634918086547752450203224546712251149064592155973342626090620714944165674055016953473475341294887308595629097007472410431532121906108088957572282026310714783107497418246512593517465039367233934654168224981093602413155513695182786967364980581565478119065103575984826265255862323181676653416967689802233214088349730947331994599695181920268130161299405995782565629800468000440941288170069450580804552732721486676013741611681944793619673798886562111764156394552401369401761640290957237757115523776564496524398167632743424880002194878959906134022876584000151040026186364933922729445416063033887021748096756407502273874073139311897811267095400718994554595717706599595291309840369068932559458206582023161200627335416474012488815016172330337260587349246890637716151044386991611573955523916598749709975716622679748797842147158726687759796825231375555889423050904597779670669542392325007347450602190569159391485653708628977505864044630073984857552417164766694174007446237442294526801441688015836679834960908965063795498787911525043365680105157251534733012502707949586129922040981734237315570322398309605732325741869439738326210465859465676096641936226281199767693354773928874388433433619697484325389804752325569617438122436340776811759892840966332713004452194028293166786594323316988588540548337522771148090464530294831596457585835024566018309518347915085787882246767059251983592015486463678669596438592049008314992556342253597099170817261519193110958315582579579612590897973375077675322925722167305656337802318288366746967854216485913798801485378624760127419739516066805063615298186443155714847814227168397129307200659528151215347298459700123443326572253651823725673379629800162640998646395994184482388600983767597362373264516098864159026279963726949742425428965389974474206288539025523008779505101179403183530399923607128711649749417952856834146668247431995446772474542494576842294761706230522253316484353430938708094756603913651373251537309372016056269711748597099537816245334412718722673658907648750157979936216611490736992538374477600849705624013181091770128676485069581054048874685904083050140375491505461484946125125451337979611764072862286605372712106006826370411836898330301429634452349794501412248777505760614344490849783569014504371505461770328495059377607202264878613571439464276520675474725198021564621051600119505652211213532992622202360790091815754312912492831778390646659560040690459901136056449162132579354760291911193820625422431352244142409372672255981998554730721402236896068017291399002608524659494733156458560468454286972744117043980326910174676178911707063103605254915304021061697977849611533820629613317114846889476696181908015744691773684581421721766116278136401642504413267688296553061773640889487079941079523319237250497373798734700149432993920460571528295808178065313882435208470362653529114065796062572729665041898351559680918279839147245393054880997783582680218593925594607624500090379662522764884879472497228739168678792217895918597323042889902923183460534005812014216501363645976671584231574633653237845999560572585757923903205441980717507754148387516844031980736798705250383427695858961777809551804058339251044381692967273519833836087499347445601294743806210482771755946615364138025776699592214328553465384862908829172871443071701627260637948355406567656586196261571857797351973872753455115341974403208689931822888840618095837856835836394220964167373693182043337821269170972524622932791811888912799516823430014684735838761857776779589974226842805074532243035588934778154324933509023535093506616335938383230021260887567310329094908408756605538385397234006271831785200944648397254513110833878153213909414855156147406580199544926314022129562346840811295917348374741554351275966099497539583772438559776254413455134392518272577650575336568062777244668565133254732650588948151145265262483174452321786600631078667589115400895685481443896662624596421972072634179998128521551328524409147039181155195254079054125314833707693253478332206243285173108787414261108600363476728627922180452603493453425271127307705393556306352032635208921648129782670552618600278257768436977627400984290219034868885655233425867631329453946124234192945444292062390064139287501070023602474691217791123210303476034915878041468974260381740828122980062146438949536001669362613825058563639940617077400121977921846377164005316723309241731235427352206528561532205796843631685579889554180615071319939092634080756482668988152398561724049845236882408823368740724293855662938714848076386745237708153888259668172851739419865414324087115957051254617425968124768603533017735321784079001850457325218829987911483131047432710646357341089726726268908301963807638384000153712817560155006091798147666549321736102030430275572850304627126716322739932121477170815946271923065311867369532267887377248219996879400509573450413921221205456088819521230510667781563476106206963190199926903895644156241024327814735639665740125951619966598339326080242254271213340903963049744522583041693089877597632573932526178555920706300304747852396865431378278487499260694027311870364355410328667112749998467439373896003064860381390956802707851152642580551808484506908569732595512165106587801736771619118518777303548767371525823564478594570943150422943471819366503424051758233597273684831997197296226005537112653183943361132860240388669248557201867337362480675098941420786903330080052975972994678444503888277589320711001095589217883075728263558182980761933023136478190685967473848614410589586742282218929572405880168032768662254225628649076169101399729794796356267028950517111994339221184328582454650116709719362617008710352054818584996741050395663202561403165353399920824824813672014368423783327933853524295735698077629063531327012611}
\end{document}
-
-
1@MaoYiyi
siunitx
only does groups of 3, because it is designed to follow the SI standards. If your number is from an external application then I would use an external tool to group the digits appropriately. Otherwise I suggest you ask a separate question on this site. Feb 25, 2014 at 8:28 -
Remark, this implementation is understandably fragile because it relies on the exact number of grouping layers created by
siunitx
package. In newer versions it's broken, refer to errors - How to show extremely large number in overleaf? - TeX - LaTeX Stack Exchange. Mar 25, 2023 at 16:19