I've made some small changes, the code below is the most current version, I've tried setting a size to the main frame, tried changing the anchor settings for the layer but it's never in the right place it's always offset a little.
I created a paste for you here.
https://paste.ee/p/zzGka
The XML code is on one tab and the LUA Code on another tab.
Lua Code:
local TabName="AMD";
local TabID=CharacterFrame.numTabs+1;
local Tab=CreateFrame("Button", "$parentTab"..TabID, CharacterFrame, "CharacterFrameTabTemplate");
PanelTemplates_SetNumTabs(CharacterFrame, TabID);
Tab:SetPoint("LEFT", "$parentTab"..(TabID-1), "RIGHT", -16, 0);
Tab:SetText(TabName);
Tab:SetID(TabID);
tinsert(CHARACTERFRAME_SUBFRAMES, "AMD_TabOnCharacterFrame");
hooksecurefunc("CharacterFrameTab_OnClick", function(self, button)
if self:GetID() == TabID then
ToggleCharacter("AMD_TabOnCharacterFrame")
end
end)